commit b0f563980df1965c2f2ec6b559195ecbc4438156
parent 258e7c6e65099ade185cb7965865529f7d2cb4fa
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 14 Jul 2020 17:22:08 +0200
tweaks: elide an unneeded call of strlen(), and copy NUL byte with string
Diffstat:
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -2610,7 +2610,7 @@ char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *list
mzero[common_len] = '\0';
/* Cover also the case of the user specifying a relative path. */
- glued = charalloc(strlen(present_path) + strlen(mzero) + 1);
+ glued = charalloc(strlen(present_path) + common_len + 1);
sprintf(glued, "%s%s", present_path, mzero);
if (num_matches == 1 && (is_dir(mzero) || is_dir(glued)))
@@ -2619,8 +2619,7 @@ char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *list
/* If the matches have something in common, copy that part. */
if (common_len != *place) {
buf = charealloc(buf, common_len + 1);
- memmove(buf + common_len, buf + *place, 1);
- strncpy(buf, mzero, common_len);
+ strcpy(buf, mzero);
*place = common_len;
} else if (num_matches == 1)
beep();