From: Guy Harris Date: Sun, 9 Aug 2015 18:04:53 +0000 (-0700) Subject: Clean up signed_relts_print() some more. X-Git-Tag: tcpdump-4.9.0-bp~73 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/4e85180c53c1c8992c2979f6ad0ba4375c02203d Clean up signed_relts_print() some more. If it's not < 0, it's not -2147483648; check for negative values first. Don't calculate the value for -2147483648 by hand, print a - and then have unsigned_relts_print() calculate the value for 2147483648. --- diff --git a/util-print.c b/util-print.c index d0f014fd..68f98887 100644 --- a/util-print.c +++ b/util-print.c @@ -423,22 +423,29 @@ void signed_relts_print(netdissect_options *ndo, int32_t secs) { - if (secs == -2147483648) { - /* - * -2^31; you can't fit its absolute value into a 32-bit - * signed integer. - * - * We calculate the right string by hand. - */ - ND_PRINT((ndo, "-68y5w3h14m8s")); - return; - } if (secs < 0) { - /* - * We now know -secs will fit into secs. - */ ND_PRINT((ndo, "-")); - secs = -secs; + if (secs == -2147483648) { + /* + * -2^31; you can't fit its absolute value into + * a 32-bit signed integer. + * + * Just directly pass said absolute value to + * unsigned_relts_print() directly. + * + * (XXX - does ISO C guarantee that -(-2^n), + * when calculated and cast to an n-bit unsigned + * integer type, will have the value 2^n?) + */ + unsigned_relts_print(ndo, 2147483648U); + } else { + /* + * We now know -secs will fit into an int32_t; + * negate it and pass that to unsigned_relts_print(). + */ + unsigned_relts_print(ndo, -secs); + } + return; } unsigned_relts_print(ndo, secs); }