From 133ed4e21dce810418f448d540498232cc604022 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 26 Apr 2016 14:28:01 +0200 Subject: [PATCH] tabbing: don't null-terminate a directory name on the slash but after it This fixes https://savannah.gnu.org/bugs/?47786. --- src/files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index 42576517..c4ddf1c3 100644 --- a/src/files.c +++ b/src/files.c @@ -2675,12 +2675,13 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t *num_matches = 0; null_at(&dirname, buf_len); - /* If there's a / in the name, strip out the directory part. */ + /* If there's a / in the name, split out filename and directory parts. */ slash = strrchr(dirname, '/'); if (slash != NULL) { char *wasdirname = dirname; - filename = mallocstrcpy(NULL, slash + 1); + filename = mallocstrcpy(NULL, ++slash); + /* Cut off the filename part after the slash. */ *slash = '\0'; dirname = real_dir_from_tilde(dirname); free(wasdirname);