diff --git a/misc.h b/misc.h index 2893bf09..db7d024a 100644 --- a/misc.h +++ b/misc.h @@ -387,10 +387,10 @@ StripCtrlChars *stripctrl_new_term_fn( void stripctrl_retarget(StripCtrlChars *sccpub, BinarySink *new_bs_out); void stripctrl_reset(StripCtrlChars *sccpub); void stripctrl_free(StripCtrlChars *sanpub); -char *stripctrl_string_ptrlen(ptrlen str); -static inline char *stripctrl_string(const char *str) +char *stripctrl_string_ptrlen(StripCtrlChars *sccpub, ptrlen str); +static inline char *stripctrl_string(StripCtrlChars *sccpub, const char *str) { - return stripctrl_string_ptrlen(ptrlen_from_asciz(str)); + return stripctrl_string_ptrlen(sccpub, ptrlen_from_asciz(str)); } #endif diff --git a/pscp.c b/pscp.c index 17f03dac..84d0b2b7 100644 --- a/pscp.c +++ b/pscp.c @@ -256,8 +256,9 @@ static NORETURN void bump(const char *fmt, ...) * version of a string for display, and free it automatically * afterwards. */ -#define with_stripctrl(varname, input) \ - for (char *varname = stripctrl_string(input); varname; \ +static StripCtrlChars *string_scc; +#define with_stripctrl(varname, input) \ + for (char *varname = stripctrl_string(string_scc, input); varname; \ sfree(varname), varname = NULL) /* @@ -1889,7 +1890,8 @@ static void sink(const char *targ, const char *src) stat_bytes = 0; stat_starttime = time(NULL); stat_lasttime = 0; - stat_name = stripctrl_string(stripslashes(destfname, true)); + stat_name = stripctrl_string( + string_scc, stripslashes(destfname, true)); received = 0; while (received < act.size) { @@ -2319,6 +2321,8 @@ int psftp_main(int argc, char *argv[]) stderr_bs = BinarySink_UPCAST(stderr_scc); } + string_scc = stripctrl_new(NULL, false, L'\0'); + if (list) { if (argc != 1) usage(); diff --git a/psftp.c b/psftp.c index 9d90deba..2a1479ad 100644 --- a/psftp.c +++ b/psftp.c @@ -70,8 +70,9 @@ static Seat psftp_seat[1] = {{ &psftp_seat_vt }}; * version of a string for display, and free it automatically * afterwards. */ -#define with_stripctrl(varname, input) \ - for (char *varname = stripctrl_string(input); varname; \ +static StripCtrlChars *string_scc; +#define with_stripctrl(varname, input) \ + for (char *varname = stripctrl_string(string_scc, input); varname; \ sfree(varname), varname = NULL) /* ---------------------------------------------------------------------- @@ -2863,6 +2864,8 @@ int psftp_main(int argc, char *argv[]) stderr_bs = BinarySink_UPCAST(stderr_scc); } + string_scc = stripctrl_new(NULL, false, L'\0'); + /* * If the loaded session provides a hostname, and a hostname has not * otherwise been specified, pop it in `userhost' so that diff --git a/stripctrl.c b/stripctrl.c index 90a5cd2f..04e41ee3 100644 --- a/stripctrl.c +++ b/stripctrl.c @@ -95,7 +95,7 @@ void stripctrl_reset(StripCtrlChars *sccpub) * start converting a fresh piece of data to send to a channel * that hasn't seen the previous output. */ - memset(&scc->term_utf8_decode, 0, sizeof(scc->term_utf8_decode)); + memset(&scc->utf8, 0, sizeof(scc->utf8)); memset(&scc->mbs_in, 0, sizeof(scc->mbs_in)); memset(&scc->mbs_out, 0, sizeof(scc->mbs_out)); } @@ -358,12 +358,12 @@ static void stripctrl_term_BinarySink_write( } } -char *stripctrl_string_ptrlen(ptrlen str) +char *stripctrl_string_ptrlen(StripCtrlChars *sccpub, ptrlen str) { strbuf *out = strbuf_new(); - StripCtrlChars *scc = stripctrl_new(BinarySink_UPCAST(out), false, L'?'); - put_datapl(scc, str); - stripctrl_free(scc); + stripctrl_retarget(sccpub, BinarySink_UPCAST(out)); + put_datapl(sccpub, str); + stripctrl_retarget(sccpub, NULL); return strbuf_to_str(out); }