aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/vmstat
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>2004-03-11 11:30:57 +0000
committerBruce Evans <bde@FreeBSD.org>2004-03-11 11:30:57 +0000
commitc04458955453548dd99e755efb6acc03d9f5f835 (patch)
treebffd876d2560a1e3c26982d7c3bd1d3dbed6fbe9 /usr.bin/vmstat
parent55cc37447a9f5caf86416b00ec8312385a6a8d6c (diff)
downloadsrc-c04458955453548dd99e755efb6acc03d9f5f835.tar.gz
src-c04458955453548dd99e755efb6acc03d9f5f835.zip
Fixed a misspelling of 0 as NULL.
Fixed a nearby bug. The "play it safe" code in dosysctl() was unsafe because it overran the buffer by 1 if sysctl() filled all of the buffer. Fixed a nearby style bug in output. Not just 1, but 2 extra newlines were printed at the end by "vmstat -m" and "vmstat -z". Don't print any newlines explicitly. This depends on 2 of the many formatting bugs in the corresponding sysctls. First, the sysctls return an extra newline at the end of the strings. This also messes up output from sysctl(8). Second, the sysctls return an extra newline at the beginning of the strings. This is good for separating the 2 tables output by "vmstat -mz" and for starting the header on a new line in plain sysctl output, but gives a bogus extra newline at the beginning for "vm -[m | z]" and "sysctl -n [kern.malloc | vm.zone]". Fixed some nearby style bugs in the source code: - the same line that misspelled 0 as NULL also spelled NULL as 0. - the size was doubled twice in the realloc loop. - the "play it safe" comment was misleading. Terminating the buffer is bogus because dosysctl() is only meant to work with sysctls that return strings and the terminator is part of a string. However, the kern.malloc sysctl has more than style bugs. It also doesn't return a string. Termination is needed to work around this bug.
Notes
Notes: svn path=/head/; revision=126842
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r--usr.bin/vmstat/vmstat.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 62179648c6d6..ea16ee2c9e5b 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -916,12 +916,12 @@ dosysctl(const char *name)
for (buf = NULL, bufsize = 1024; ; bufsize *= 2) {
if ((buf = realloc(buf, bufsize)) == NULL)
err(1, "realloc()");
- if (mysysctl(name, buf, &bufsize, 0, NULL) == 0)
+ bufsize--; /* Leave space for the kern.malloc fixup. */
+ if (mysysctl(name, buf, &bufsize, NULL, 0) == 0)
break;
- bufsize *= 2;
}
- buf[bufsize] = '\0'; /* play it safe */
- (void)printf("%s\n\n", buf);
+ buf[bufsize] = '\0'; /* Fix up kern.malloc not returning a string. */
+ (void)printf("%s", buf);
free(buf);
}