strbuf_humanise: use unsigned variables

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 24, 2018 at 06:52 UTC 7726d360b5ba859ae2b6ceefc5d88cc518c78063
1 file changed +5 -5
strbuf.c
+5 -5
@@ -734,18 +734,18 @@ void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
734 {
735 if (bytes > 1 << 30) {
736 strbuf_addf(buf, "%u.%2.2u GiB",
737 - (int)(bytes >> 30),
738 - (int)(bytes & ((1 << 30) - 1)) / 10737419);
737 + (unsigned)(bytes >> 30),
738 + (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
739 } else if (bytes > 1 << 20) {
740 - int x = bytes + 5243; /* for rounding */
740 + unsigned x = bytes + 5243; /* for rounding */
741 strbuf_addf(buf, "%u.%2.2u MiB",
742 x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
743 } else if (bytes > 1 << 10) {
744 - int x = bytes + 5; /* for rounding */
744 + unsigned x = bytes + 5; /* for rounding */
745 strbuf_addf(buf, "%u.%2.2u KiB",
746 x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
747 } else {
748 - strbuf_addf(buf, "%u bytes", (int)bytes);
748 + strbuf_addf(buf, "%u bytes", (unsigned)bytes);
749 }
750 }
751