diff --git a/ChangeLog b/ChangeLog index 0a1c5b67..cf0ff8b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ src/move.c (do_prev_word, do_next_word): Sort these in standard way. * src/prompt.c (do_statusbar_output): Don't move too many bytes. This fixes Savannah bug #47219 (uncovered by r5655). + * src/prompt.c (do_statusbar_output): Elide a variable. 2016-02-21 Benno Schulenberg * src/files.c (input_tab): If the first Tab added the part that all diff --git a/src/prompt.c b/src/prompt.c index 55855b6c..957c9db8 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -246,10 +246,9 @@ int do_statusbar_mouse(void) void do_statusbar_output(int *the_input, size_t input_len, bool filtering, bool *got_enter) { - size_t answer_len, i; char *output = charalloc(input_len + 1); char *char_buf = charalloc(mb_cur_max()); - int char_buf_len; + int i, char_buf_len; assert(answer != NULL); @@ -258,7 +257,6 @@ void do_statusbar_output(int *the_input, size_t input_len, output[i] = (char)the_input[i]; output[i] = '\0'; - answer_len = strlen(answer); i = 0; while (i < input_len) { @@ -284,15 +282,13 @@ void do_statusbar_output(int *the_input, size_t input_len, if (filtering && is_ascii_cntrl_char(*(output + i - char_buf_len))) continue; - /* More dangerousness fun. =) */ - answer = charealloc(answer, answer_len + char_buf_len + 1); - - assert(statusbar_x <= answer_len); + assert(statusbar_x <= strlen(answer)); + /* Insert the typed character into the existing answer string. */ + answer = charealloc(answer, strlen(answer) + char_buf_len + 1); charmove(answer + statusbar_x + char_buf_len, answer + statusbar_x, - answer_len - statusbar_x + 1); + strlen(answer) - statusbar_x + 1); strncpy(answer + statusbar_x, char_buf, char_buf_len); - answer_len += char_buf_len; statusbar_x += char_buf_len; }