Commit 553b7af3 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

files: do not use two variables for two different purposes each

Use 'slash' to point at a possible slash, use 'filename' just to
point at the real file name, and use 'wasdirname' just to point at
the dir's name before expanding it in order to be able to free it.

Also, remove two superfluous asserts: 'dirname' cannot be NULL
because it has just been mallocstrcpy'd, and checking 'num_matches'
is pointless as it would crash on the next statement anyway.
No related merge requests found
Showing with 9 additions and 11 deletions
+9 -11
......@@ -2667,27 +2667,25 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
char **cwd_tab_completion(const char *buf, bool allow_files, size_t
*num_matches, size_t buf_len)
{
char *dirname = mallocstrcpy(NULL, buf), *filename;
char *dirname = mallocstrcpy(NULL, buf);
char *slash, *filename;
size_t filenamelen;
char **matches = NULL;
DIR *dir;
const struct dirent *nextdir;
assert(dirname != NULL && num_matches != NULL);
*num_matches = 0;
null_at(&dirname, buf_len);
/* Okie, if there's a / in the buffer, strip out the directory part. */
filename = strrchr(dirname, '/');
if (filename != NULL) {
char *tmpdirname = filename + 1;
/* If there's a / in the name, strip out the directory part. */
slash = strrchr(dirname, '/');
if (slash != NULL) {
char *wasdirname = dirname;
filename = mallocstrcpy(NULL, tmpdirname);
*tmpdirname = '\0';
tmpdirname = dirname;
filename = mallocstrcpy(NULL, slash + 1);
*slash = '\0';
dirname = real_dir_from_tilde(dirname);
free(tmpdirname);
free(wasdirname);
} else {
filename = dirname;
dirname = mallocstrcpy(NULL, "./");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment