Re: [PATCH hurd] libps: update ps_emit_nice_size_t to handle arbitrarily (original) (raw)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
From: | Samuel Thibault |
---|---|
Subject: | Re: [PATCH hurd] libps: update ps_emit_nice_size_t to handle arbitrarily large size_t |
Date: | Sun, 3 Mar 2024 20:07:27 +0100 |
User-agent: | NeoMutt/20170609 (1.8.3) |
Applied, thanks!
Flavio Cruz, le dim. 03 mars 2024 12:38:19 -0500, a ecrit:
Update argument types for sprintfracvalue to reflect how big they actually are so that GCC doesn't think it needs a larger buffer than necessary. --- libps/spec.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/libps/spec.c b/libps/spec.c index 9f64703..60ae7fb 100644 --- a/libps/spec.c +++ b/libps/spec.c @@ -19,6 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <hurd.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <assert-backtrace.h> @@ -437,12 +438,12 @@ psemitnumblocks (struct procstat *ps, struct psfmtfield *field,
sizet sprintfracvalue (char *buf, - sizet value, int minvaluelen, - sizet frac, int fracscale, - int width) + uint16t value, uint8t minvaluelen, + uint16t frac, uint8t fracscale, + uint8t width) { - int valuelen = 0; - int fraclen = 0; + uint8t valuelen = 0; + uint8t fraclen = 0;
if (value >= 1000) /* the integer part */ valuelen = 4; /* values 1000-1023 */ @@ -462,9 +463,9 @@ sprintfracvalue (char *buf, frac /= 10;
if (fraclen > 0) - sprintf (buf, "%zd.%0*zd", value, fraclen, frac); + sprintf (buf, "%" PRIu16 ".%0*" PRIu16, value, fraclen, frac); else - sprintf (buf, "%zd", value); + sprintf (buf, "%" PRIu16, value);
return strlen (buf); } @@ -492,11 +493,14 @@ errort psemitnicesizet (struct procstat *ps, struct psfmtfield *field, struct psstream *stream) { - char buf[21]; + char buf[20]; sizet value = FGPROCSTAT (field, sizet)(ps); - char *sfx = " KMG"; + char *sfx = " KMGTPE"; sizet frac = 0;
+ Staticassert (sizeof (sizet) <= 8,_ _+ "psemitnicesizet can only emit sizet up to 8 bytes long.");_ _+_ _while (value >= 1024) { frac = ((value & 0x3FF) * 1000) >> 10; -- 2.39.2
-- Samuel
Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.
- [PATCH hurd] libps: update ps_emit_nice_size_t to handle arbitrarily large size_t, Flavio Cruz, 2024/03/03
- Re: [PATCH hurd] libps: update ps_emit_nice_size_t to handle arbitrarily large size_t,Samuel Thibault <=
- Prev by Date:Re: [PATCH hurd] rumpdisk: do not open device if block size is 0
- Next by Date:Re: [PATCH 1/1 hurd] ext2fs: New default: use xattrs to store translator records
- Previous by thread:[PATCH hurd] libps: update ps_emit_nice_size_t to handle arbitrarily large size_t
- Next by thread:[PATCH hurd] MAKEDEV: when creating devices, ensure the underlying files are either block/char devices or directories
- Index(es):