summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2006-02-14 11:57:02 +0000
committerbde <bde@FreeBSD.org>2006-02-14 11:57:02 +0000
commitfce3a7325a8849b58c71b811b5c38d1680f881c7 (patch)
tree80a8d72dae88a676c301df8eb80b0894615881b6 /usr.bin
parente85d27fb5cdffff450e7d4f4c932ae2202915d44 (diff)
downloadFreeBSD-src-fce3a7325a8849b58c71b811b5c38d1680f881c7.zip
FreeBSD-src-fce3a7325a8849b58c71b811b5c38d1680f881c7.tar.gz
Fix some minor bugs:
Always use snprintf()'s return value, since discarding it is a style bug at best and using it here gives slightly simpler code and better error checking. Use snprintf() in putlongdouble() the same as in putfloat(). (1.25 changed most sprintf()'s to snprintf()'s to fix non-bugs without changing the logic to use the result of snprintf(); 1.27 restored one of the sprintf()s by cloning a stale version of putfloat().) Don't print a too-long field in the unlikely case that the fallback to M units in putint() leaves the field still too long. (The fallback to printing stars was lost in rev.1.58 when the fallback to M units was added.)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/systat/vmstat.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index 7709a05..2fc003a 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -670,6 +670,7 @@ static void
putint(n, l, lc, w)
int n, l, lc, w;
{
+ int snr;
char b[128];
move(l, lc);
@@ -678,11 +679,16 @@ putint(n, l, lc, w)
addch(' ');
return;
}
- snprintf(b, sizeof(b), "%*d", w, n);
- if ((int)strlen(b) > w)
- snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000);
- if ((int)strlen(b) > w)
- snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000);
+ snr = snprintf(b, sizeof(b), "%*d", w, n);
+ if (snr != w)
+ snr = snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000);
+ if (snr != w)
+ snr = snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000);
+ if (snr != w) {
+ while (w-- > 0)
+ addch('*');
+ return;
+ }
addstr(b);
}
@@ -691,6 +697,7 @@ putfloat(f, l, lc, w, d, nz)
double f;
int l, lc, w, d, nz;
{
+ int snr;
char b[128];
move(l, lc);
@@ -699,10 +706,10 @@ putfloat(f, l, lc, w, d, nz)
addch(' ');
return;
}
- snprintf(b, sizeof(b), "%*.*f", w, d, f);
- if ((int)strlen(b) > w)
- snprintf(b, sizeof(b), "%*.0f", w, f);
- if ((int)strlen(b) > w) {
+ snr = snprintf(b, sizeof(b), "%*.*f", w, d, f);
+ if (snr != w)
+ snr = snprintf(b, sizeof(b), "%*.0f", w, f);
+ if (snr != w) {
while (--w >= 0)
addch('*');
return;
@@ -715,6 +722,7 @@ putlongdouble(f, l, lc, w, d, nz)
long double f;
int l, lc, w, d, nz;
{
+ int snr;
char b[128];
move(l, lc);
@@ -723,10 +731,10 @@ putlongdouble(f, l, lc, w, d, nz)
addch(' ');
return;
}
- sprintf(b, "%*.*Lf", w, d, f);
- if ((int)strlen(b) > w)
- sprintf(b, "%*.0Lf", w, f);
- if ((int)strlen(b) > w) {
+ snr = snprintf(b, sizeof(b), "%*.*Lf", w, d, f);
+ if (snr != w)
+ snr = snprintf(b, sizeof(b), "%*.0Lf", w, f);
+ if (snr != w) {
while (--w >= 0)
addch('*');
return;
OpenPOWER on IntegriCloud