From: Francois Fleuret Date: Sat, 5 Jun 2010 23:26:40 +0000 (+0200) Subject: Fixed a bug when given a filename of length 0 as argument (i.e. ""). X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=dus.git;a=commitdiff_plain;h=622f9a38a823a17f47dfcc2956a3b3606299d949 Fixed a bug when given a filename of length 0 as argument (i.e. ""). --- 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);