]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Clean up signed_relts_print() some more.
authorGuy Harris <[email protected]>
Sun, 9 Aug 2015 18:04:53 +0000 (11:04 -0700)
committerFrancois-Xavier Le Bail <[email protected]>
Wed, 18 Jan 2017 08:16:38 +0000 (09:16 +0100)
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.

util-print.c

index d0f014fdf77d7379391541255a1982f881c3d4f1..68f988873770874b229bb3d8cb277e8530316dc2 100644 (file)
@@ -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);
 }