From 6747142cd70de69224c3b09a6fd339eb6333e297 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 12 Feb 2020 11:12:34 +0100 Subject: [PATCH] tweaks: remove some redundant filtering, and thus elide a parameter The few calls of the injection routines that had 'filtering' set to TRUE have already filtered out ASCII control codes earlier on. And in the case of injecting a completion, this completion only contains word-forming characters -- and if the user somehow added a control code to the word-forming characters, then nano should NOT filter it out, so in fact that setting of 'filtering' to TRUE was mistaken. Note that this filtering did not filter out 0x7F (DEL). But that is fine: it should not occur in the input stream at that point anyway, as it gets translated to either KEY_DC or KEY_BACKSPACE earlier in the keyboard parsing routines. --- src/nano.c | 8 ++------ src/prompt.c | 10 +++------- src/proto.h | 4 ++-- src/text.c | 12 ++++++------ 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/nano.c b/src/nano.c index 0e41c371..436a6262 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1565,7 +1565,7 @@ void do_input(void) /* Insert all bytes in the input buffer into the edit buffer * at once, filtering out any ASCII control codes. */ puddle[depth] = '\0'; - inject(puddle, depth, TRUE); + inject(puddle, depth); /* Empty the input buffer. */ free(puddle); @@ -1656,7 +1656,7 @@ void do_input(void) /* The user typed output_len multibyte characters. Add them to the edit * buffer, filtering out ASCII control characters when filtering is TRUE. */ -void inject(char *output, size_t output_len, bool filtering) +void inject(char *output, size_t output_len) { char onechar[MAXCHARLEN]; int charlen; @@ -1682,10 +1682,6 @@ void inject(char *output, size_t output_len, bool filtering) i += charlen; - /* If controls are not allowed, ignore an ASCII control character. */ - if (filtering && is_ascii_cntrl_char(*(output + i - charlen))) - continue; - /* Make room for the new character and copy it into the line. */ openfile->current->data = charealloc(openfile->current->data, current_len + charlen + 1); diff --git a/src/prompt.c b/src/prompt.c index ad6f5220..f872038e 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -115,7 +115,7 @@ int do_statusbar_input(bool *finished) if ((shortcut || get_key_buffer_len() == 0) && kbinput != NULL) { /* Inject all characters in the input buffer at once, filtering out * control characters. */ - inject_into_answer(kbinput, kbinput_len, TRUE); + inject_into_answer(kbinput, kbinput_len); /* Empty the input buffer. */ kbinput_len = 0; @@ -185,7 +185,7 @@ int do_statusbar_input(bool *finished) /* The user typed input_len multibyte characters. Add them to the answer, * filtering out ASCII control characters if filtering is TRUE. */ -void inject_into_answer(int *the_input, size_t input_len, bool filtering) +void inject_into_answer(int *the_input, size_t input_len) { char *output = charalloc(input_len + 1); char onechar[MAXCHARLEN]; @@ -206,10 +206,6 @@ void inject_into_answer(int *the_input, size_t input_len, bool filtering) j += charlen; - /* When filtering, skip any ASCII control character. */ - if (filtering && is_ascii_cntrl_char(*(output + j - charlen))) - continue; - /* Insert the typed character into the existing answer string. */ answer = charealloc(answer, strlen(answer) + charlen + 1); memmove(answer + typing_x + charlen, answer + typing_x, @@ -339,7 +335,7 @@ void do_statusbar_verbatim_input(void) kbinput = get_verbatim_kbinput(bottomwin, &kbinput_len); - inject_into_answer(kbinput, kbinput_len, FALSE); + inject_into_answer(kbinput, kbinput_len); free(kbinput); } diff --git a/src/proto.h b/src/proto.h index 243d400d..30449d27 100644 --- a/src/proto.h +++ b/src/proto.h @@ -444,10 +444,10 @@ void confirm_margin(void); #endif void unbound_key(int code); bool okay_for_view(const keystruct *shortcut); -void inject(char *output, size_t output_len, bool filtering); +void inject(char *output, size_t output_len); /* Most functions in prompt.c. */ -void inject_into_answer(int *the_input, size_t input_len, bool filtering); +void inject_into_answer(int *the_input, size_t input_len); void do_statusbar_home(void); void do_statusbar_end(void); void do_statusbar_left(void); diff --git a/src/text.c b/src/text.c index 5f0519fe..54e95ade 100644 --- a/src/text.c +++ b/src/text.c @@ -69,7 +69,7 @@ void do_tab(void) { #ifdef ENABLE_COLOR if (openfile->syntax && openfile->syntax->tab) - inject(openfile->syntax->tab, strlen(openfile->syntax->tab), FALSE); + inject(openfile->syntax->tab, strlen(openfile->syntax->tab)); else #endif #ifndef NANO_TINY @@ -80,12 +80,12 @@ void do_tab(void) memset(spaces, ' ', length); spaces[length] = '\0'; - inject(spaces, length, FALSE); + inject(spaces, length); free(spaces); } else #endif - inject((char *)"\t", 1, FALSE); + inject((char *)"\t", 1); } #ifndef NANO_TINY @@ -3156,7 +3156,7 @@ void do_verbatim_input(void) keycodes[count] = '\0'; /* Insert the keystroke verbatim, without filtering control characters. */ - inject(keycodes, count, FALSE); + inject(keycodes, count); free(keycodes); free(kbinput); @@ -3303,8 +3303,8 @@ void complete_a_word(void) UNSET(BREAK_LONG_LINES); #endif /* Inject the completion into the buffer. */ - inject(&completion[shard_length], - strlen(completion) - shard_length, TRUE); + inject(&completion[shard_length], strlen(completion) - shard_length); + #ifdef ENABLE_WRAPPING /* If needed, reenable wrapping and wrap the current line. */ if (was_set_wrapping) {