From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 6/6] strbuf_humanise: use unsigned variables
Date: Tue, 24 Jul 2018 06:52:29 -0400 [thread overview]
Message-ID: <20180724105229.GF17165@sigill.intra.peff.net> (raw)
In-Reply-To: <20180724104852.GA14638@sigill.intra.peff.net>
All of the numeric formatting done by this function uses
"%u", but we pass in a signed "int". The actual range
doesn't matter here, since the conditional makes sure we're
always showing reasonably small numbers. And even gcc's
format-checker does not seem to mind. But it's potentially
confusing to a reader of the code to see the mismatch.
Signed-off-by: Jeff King <peff@peff.net>
---
strbuf.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index db9069c937..54f29bbb23 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -734,18 +734,18 @@ void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
{
if (bytes > 1 << 30) {
strbuf_addf(buf, "%u.%2.2u GiB",
- (int)(bytes >> 30),
- (int)(bytes & ((1 << 30) - 1)) / 10737419);
+ (unsigned)(bytes >> 30),
+ (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
} else if (bytes > 1 << 20) {
- int x = bytes + 5243; /* for rounding */
+ unsigned x = bytes + 5243; /* for rounding */
strbuf_addf(buf, "%u.%2.2u MiB",
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
} else if (bytes > 1 << 10) {
- int x = bytes + 5; /* for rounding */
+ unsigned x = bytes + 5; /* for rounding */
strbuf_addf(buf, "%u.%2.2u KiB",
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
} else {
- strbuf_addf(buf, "%u bytes", (int)bytes);
+ strbuf_addf(buf, "%u bytes", (unsigned)bytes);
}
}
--
2.18.0.542.g2bf2fc4f7e
prev parent reply other threads:[~2018-07-24 10:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-24 10:48 [PATCH 0/6] use size_t in iconv/strbuf Jeff King
2018-07-24 10:50 ` [PATCH 1/6] reencode_string: use st_add/st_mult helpers Jeff King
2018-07-24 10:50 ` [PATCH 2/6] reencode_string: use size_t for string lengths Jeff King
2018-07-24 10:51 ` [PATCH 3/6] strbuf: use size_t for length in intermediate variables Jeff King
2018-07-24 10:51 ` [PATCH 4/6] strbuf_readlink: use ssize_t Jeff King
2018-07-24 10:51 ` [PATCH 5/6] pass st.st_size as hint for strbuf_readlink() Jeff King
2018-07-25 18:41 ` Torsten Bögershausen
2018-07-26 6:09 ` Jeff King
2018-07-24 10:52 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180724105229.GF17165@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).