aboutsummaryrefslogtreecommitdiff
path: root/toys/other/vmstat.c
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-09-01 19:16:06 -0500
committerRob Landley <rob@landley.net>2015-09-01 19:16:06 -0500
commit7d58b3085c6ebaa02cf567f25a741b878ee0a87c (patch)
tree343b1302086c9f95c438fd8d462dc6375be532f7 /toys/other/vmstat.c
parentb1b0399dc701f3c9af19a09164a4f536bc00eb2c (diff)
downloadtoybox-7d58b3085c6ebaa02cf567f25a741b878ee0a87c.tar.gz
vmstat: reset header pointer when looping
Modifying the headers pointer when printing the headers causes a buffer overrun the second time they are printed. Use a local header pointer that is reset to the beginning of the buffer for each loop.
Diffstat (limited to 'toys/other/vmstat.c')
-rw-r--r--toys/other/vmstat.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index 9a38e452..5b79702b 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -96,14 +96,14 @@ void vmstat_main(void)
// Print headers
if (rows>3 && !(loop % (rows-3))) {
+ const char *header = headers;
if (isatty(1)) terminal_size(0, &rows);
else rows = 0;
printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
-
for (i=0; i<sizeof(lengths); i++) {
- printf(" %*s"+!i, lengths[i], headers);
- headers += strlen(headers)+1;
+ printf(" %*s"+!i, lengths[i], header);
+ header += strlen(header)+1;
}
xputc('\n');
}