diff -u nano/files.c nano-stripone/files.c --- nano/files.c Fri Feb 7 22:33:29 2003 +++ nano-stripone/files.c Sat Feb 8 13:40:22 2003 @@ -2395,13 +2395,15 @@ { char *tmp; + assert(foo != NULL); /* Don't strip the root dir */ - if (!strcmp(foo, "/")) + if (*foo == '\0' || strcmp(foo, "/") == 0) return; - tmp = foo + strlen(foo); + tmp = foo + strlen(foo) - 1; + assert(tmp >= foo); if (*tmp == '/') - tmp--; + *tmp == '\0'; while (*tmp != '/' && tmp != foo) tmp--; @@ -2463,6 +2465,7 @@ sprintf(filelist[i], "%s/%s", path, next->d_name); i++; } + closedir(dir); if (*longest > COLS - 1) *longest = COLS - 1; @@ -2838,8 +2841,10 @@ if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { striponedir(path); - if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) + if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { + free(path); path = getcwd(NULL, PATH_MAX + 1); + } } #ifndef DISABLE_OPERATINGDIR