From: Alan Cox Date: Sat, 16 May 2015 15:44:26 +0000 (+0100) Subject: df: fix multiple bugs X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5c468432f64d4b4dc81690c63d7030e2a1eb9363;p=FUZIX.git df: fix multiple bugs - sizeof(number) is not number but 1 or 2 - check strtok return rather than trying to play with NULL Not clear with is the root cause of the trs80 df crash but at least it works now --- diff --git a/Applications/util/df.c b/Applications/util/df.c index 074b6050..b2830af4 100644 --- a/Applications/util/df.c +++ b/Applications/util/df.c @@ -125,13 +125,14 @@ void df_all(void) f = fopen("/etc/mtab", "r"); if (f) { - while (fgets(tmp, sizeof(MTAB_LINE), f)) { - dev = strtok(tmp, " "); - mntpt = strtok(NULL, " "); - df_path(mntpt); + while (fgets(tmp, MTAB_LINE, f)) { + dev = strtok(tmp, " "); + mntpt = strtok(NULL, " "); + if (mntpt) + df_path(mntpt); } fclose(f); - }else{ + } else { fprintf(stderr, "df: cannot open /etc/mtab: %s\n", strerror(errno)); } } @@ -156,9 +157,11 @@ const char *devname(dev_t devno) continue; if (fstat.st_rdev != devno) continue; + closedir(dp); return namebuf; } } + closedir(dp); sprintf(namebuf, "%d", devno); return namebuf;