From 622f9a38a823a17f47dfcc2956a3b3606299d949 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 6 Jun 2010 01:26:40 +0200 Subject: [PATCH] Fixed a bug when given a filename of length 0 as argument (i.e. ""). --- dus.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dus.c b/dus.c index e00d3df..780d360 100644 --- a/dus.c +++ b/dus.c @@ -85,7 +85,7 @@ int ignore_entry(const char *name) { return strcmp(name, ".") == 0 || strcmp(name, "..") == 0 || - (ignore_dotfiles && name[0] == '.' && name[1] != '/'); + (ignore_dotfiles && name[0] == '.' && name[1] != '/'); } size_sum_t entry_size(const char *name) { @@ -395,7 +395,7 @@ static struct option long_options[] = { }; int main(int argc, char **argv) { - int c; + int c, l; struct entry_node *root; struct winsize win; @@ -449,8 +449,9 @@ int main(int argc, char **argv) { if (optind < argc) { while (optind < argc) { - if(argv[optind][strlen(argv[optind]) - 1] == '/') { - argv[optind][strlen(argv[optind]) - 1] = '\0'; + l = strlen(argv[optind]); + if(l > 0 && argv[optind][l - 1] == '/') { + argv[optind][l - 1] = '\0'; root = push_dir_content(argv[optind++], root); } else { root = push_entry(argv[optind++], root); -- 2.20.1