Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Nov 2017 00:05:38 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r326073 - head/usr.bin/systat
Message-ID:  <20171122220538.GT2272@kib.kiev.ua>
In-Reply-To: <20171123021646.M1933@besplex.bde.org>
References:  <201711211955.vALJtWhg047906@repo.freebsd.org> <20171122071838.R1172@besplex.bde.org> <20171122103917.GS2272@kib.kiev.ua> <20171123021646.M1933@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Nov 23, 2017 at 04:24:13AM +1100, Bruce Evans wrote:
> sysctl/sysctl.c:
>    sysctl(8) has bogus support for prettyprinting struct vmtotal (sysctl
>    shouldn't have any prettyprinting, especially not for structs that have
>    specialized programs to print them and much more).  This uses intmax_t
>    for all calculations and printing except for the int16_t fields, so it
>    automatically benefited from the expansion.  However since it uses a
>    correct type (signed, and not restricted to 64 bits), it now has minor
>    type errors -- it dowcasts the uint64_t to intmax_t wheen the latter is
>    64 bits.  Its Makefile uses a fairly high WARNS, so if its type errors
>    were fatal then printf format checking would have detected them (but
>    not non-fatal errors involving downcasting).

Below is the cast to uintmax_t and unsigned format for sysctl(8).

diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index e1bf4e31914..92685a8171b 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -625,15 +625,15 @@ S_vmtotal(size_t l2, void *p)
 	    "%hd Sleep: %hd)\n",
 	    v->t_rq, v->t_dw, v->t_pw, v->t_sl);
 	printf(
-	    "Virtual Memory:\t\t(Total: %jdK Active: %jdK)\n",
-	    (intmax_t)v->t_vm * pageKilo, (intmax_t)v->t_avm * pageKilo);
-	printf("Real Memory:\t\t(Total: %jdK Active: %jdK)\n",
-	    (intmax_t)v->t_rm * pageKilo, (intmax_t)v->t_arm * pageKilo);
-	printf("Shared Virtual Memory:\t(Total: %jdK Active: %jdK)\n",
-	    (intmax_t)v->t_vmshr * pageKilo, (intmax_t)v->t_avmshr * pageKilo);
-	printf("Shared Real Memory:\t(Total: %jdK Active: %jdK)\n",
-	    (intmax_t)v->t_rmshr * pageKilo, (intmax_t)v->t_armshr * pageKilo);
-	printf("Free Memory:\t%jdK", (intmax_t)v->t_free * pageKilo);
+	    "Virtual Memory:\t\t(Total: %juK Active: %juK)\n",
+	    (uintmax_t)v->t_vm * pageKilo, (uintmax_t)v->t_avm * pageKilo);
+	printf("Real Memory:\t\t(Total: %juK Active: %juK)\n",
+	    (uintmax_t)v->t_rm * pageKilo, (uintmax_t)v->t_arm * pageKilo);
+	printf("Shared Virtual Memory:\t(Total: %juK Active: %juK)\n",
+	    (uintmax_t)v->t_vmshr * pageKilo, (uintmax_t)v->t_avmshr * pageKilo);
+	printf("Shared Real Memory:\t(Total: %juK Active: %juK)\n",
+	    (uintmax_t)v->t_rmshr * pageKilo, (uintmax_t)v->t_armshr * pageKilo);
+	printf("Free Memory:\t%juK", (uintmax_t)v->t_free * pageKilo);
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171122220538.GT2272>