tabbing: properly terminate the answer when the sole match is a folder

When there is just one match when <Tab> is pressed, and this match
is a directory, then a slash is added to 'shared', overwriting the
terminating NUL character.  So, strcpy() cannot be used for copying
this 'shared' string, but strncpy() is needed, and the result needs
to be NUL terminated afterward.

This fixes https://savannah.gnu.org/bugs/?58826.

Bug existed since commit b0f56398 from eleven days ago.
master
Benno Schulenberg 2020-07-25 13:19:19 +02:00
parent 5ca4e9f5b3
commit 7157f5a3ce
1 changed files with 2 additions and 1 deletions

View File

@ -2566,7 +2566,8 @@ char *input_tab(char *morsel, size_t *place, void (*refresh_func)(void), bool *l
/* If the matches have something in common, copy that part. */
if (common_len != *place) {
morsel = charealloc(morsel, common_len + 1);
strcpy(morsel, shared);
strncpy(morsel, shared, common_len);
morsel[common_len] = '\0';
*place = common_len;
} else if (num_matches == 1)
beep();