summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruqs <uqs@FreeBSD.org>2013-04-20 12:41:05 +0000
committeruqs <uqs@FreeBSD.org>2013-04-20 12:41:05 +0000
commit53649a9504c0ce71dc947f113312786ad27d16e9 (patch)
treedb07cd5f7990c8563389525a05a1adb413ed0c97
parentf497b9bd3e067fb227ed0ab5f667876dfa54d061 (diff)
downloadFreeBSD-src-53649a9504c0ce71dc947f113312786ad27d16e9.zip
FreeBSD-src-53649a9504c0ce71dc947f113312786ad27d16e9.tar.gz
bin/df: Fix unitialized use in prtstat
While here: - use NULL in the context of pointers - use memset instead of bzero throughout the file - free memory to appease clang static analyzer Found by: Coverity Scan (the UNINIT one)
-rw-r--r--bin/df/df.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/df/df.c b/bin/df/df.c
index 77b7a40..b83603f 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -114,6 +114,7 @@ main(int argc, char *argv[])
fstype = "ufs";
(void)setlocale(LC_ALL, "");
+ memset(&maxwidths, 0, sizeof(maxwidths));
memset(&totalbuf, 0, sizeof(totalbuf));
totalbuf.f_bsize = DEV_BSIZE;
strlcpy(totalbuf.f_mntfromname, "total", MNAMELEN);
@@ -200,7 +201,7 @@ main(int argc, char *argv[])
} else {
/* just the filesystems specified on the command line */
mntbuf = malloc(argc * sizeof(*mntbuf));
- if (mntbuf == 0)
+ if (mntbuf == NULL)
err(1, "malloc()");
mntsize = 0;
/* continued in for loop below */
@@ -209,13 +210,13 @@ main(int argc, char *argv[])
/* iterate through specified filesystems */
for (; *argv; argv++) {
if (stat(*argv, &stbuf) < 0) {
- if ((mntpt = getmntpt(*argv)) == 0) {
+ if ((mntpt = getmntpt(*argv)) == NULL) {
warn("%s", *argv);
rv = 1;
continue;
}
} else if (S_ISCHR(stbuf.st_mode)) {
- if ((mntpt = getmntpt(*argv)) == 0) {
+ if ((mntpt = getmntpt(*argv)) == NULL) {
mdev.fspec = *argv;
mntpath = strdup("/tmp/df.XXXXXX");
if (mntpath == NULL) {
@@ -282,7 +283,7 @@ main(int argc, char *argv[])
mntbuf[mntsize++] = statfsbuf;
}
- bzero(&maxwidths, sizeof(maxwidths));
+ memset(&maxwidths, 0, sizeof(maxwidths));
for (i = 0; i < mntsize; i++) {
if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) {
update_maxwidths(&maxwidths, &mntbuf[i]);
@@ -295,6 +296,7 @@ main(int argc, char *argv[])
prtstat(&mntbuf[i], &maxwidths);
if (cflag)
prtstat(&totalbuf, &maxwidths);
+ free(mntbuf);
return (rv);
}
@@ -309,7 +311,7 @@ getmntpt(const char *name)
if (!strcmp(mntbuf[i].f_mntfromname, name))
return (mntbuf[i].f_mntonname);
}
- return (0);
+ return (NULL);
}
/*
OpenPOWER on IntegriCloud