diff --git a/src/nano.c b/src/nano.c index e8bd5bad64fff7278913eb14d481ef2d80734ffb..d0fed49206c12987fcd6ee1297d44693e56e04fb 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1812,7 +1812,7 @@ int do_mouse(void) * TRUE. */ void do_output(char *output, size_t output_len, bool allow_cntrls) { - char *char_buf = charalloc(mb_cur_max()); + char onechar[mb_cur_max()]; int char_len; size_t current_len = strlen(openfile->current->data); size_t i = 0; @@ -1832,7 +1832,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) output[i] = '\n'; /* Get the next multibyte character. */ - char_len = parse_mbchar(output + i, char_buf, NULL); + char_len = parse_mbchar(output + i, onechar, NULL); i += char_len; @@ -1853,7 +1853,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) charmove(openfile->current->data + openfile->current_x + char_len, openfile->current->data + openfile->current_x, current_len - openfile->current_x + 1); - strncpy(openfile->current->data + openfile->current_x, char_buf, + strncpy(openfile->current->data + openfile->current_x, onechar, char_len); current_len += char_len; openfile->totsize++; @@ -1893,8 +1893,6 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) refresh_needed = TRUE; #endif - free(char_buf); - openfile->placewewant = xplustabs(); #ifndef DISABLE_COLOR diff --git a/src/prompt.c b/src/prompt.c index 400ad6f6ef5e5b735df6ac1314e8b906c18cd12d..1d3c4941ac1b808287dee69725b2543af34c0a50 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -197,7 +197,7 @@ void do_statusbar_output(int *the_input, size_t input_len, bool filtering) { char *output = charalloc(input_len + 1); - char *char_buf = charalloc(mb_cur_max()); + char onechar[mb_cur_max()]; int i, char_len; /* Copy the typed stuff so it can be treated. */ @@ -213,7 +213,7 @@ void do_statusbar_output(int *the_input, size_t input_len, output[i] = '\n'; /* Interpret the next multibyte character. */ - char_len = parse_mbchar(output + i, char_buf, NULL); + char_len = parse_mbchar(output + i, onechar, NULL); i += char_len; @@ -225,12 +225,11 @@ void do_statusbar_output(int *the_input, size_t input_len, answer = charealloc(answer, strlen(answer) + char_len + 1); charmove(answer + statusbar_x + char_len, answer + statusbar_x, strlen(answer) - statusbar_x + 1); - strncpy(answer + statusbar_x, char_buf, char_len); + strncpy(answer + statusbar_x, onechar, char_len); statusbar_x += char_len; } - free(char_buf); free(output); update_the_statusbar(); diff --git a/src/text.c b/src/text.c index fc92d11c29804a40106fcce143024bfd49339516..8579068c84a3eb46d22ca221ba1f0f55bdf6434a 100644 --- a/src/text.c +++ b/src/text.c @@ -1682,25 +1682,19 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl) size_t indent_length(const char *line) { size_t len = 0; - char *blank_mb; - int blank_mb_len; - - assert(line != NULL); - - blank_mb = charalloc(mb_cur_max()); + char onechar[mb_cur_max()]; + int charlen; while (*line != '\0') { - blank_mb_len = parse_mbchar(line, blank_mb, NULL); + charlen = parse_mbchar(line, onechar, NULL); - if (!is_blank_mbchar(blank_mb)) + if (!is_blank_mbchar(onechar)) break; - line += blank_mb_len; - len += blank_mb_len; + line += charlen; + len += charlen; } - free(blank_mb); - return len; } #endif /* !NANO_TINY || !DISABLE_JUSTIFY */