]> rtime.felk.cvut.cz Git - can-utils.git/commitdiff
candump: fix off-by-one error in dropcount calculation
authorUrs Thuermann <urs@isnogud.escape.de>
Thu, 23 Oct 2014 17:23:00 +0000 (19:23 +0200)
committerOliver Hartkopp <socketcan@hartkopp.net>
Thu, 23 Oct 2014 17:27:09 +0000 (19:27 +0200)
Calculations using unsigned integer types are done modulo U*INT_MAX+1,
so you get the correct difference of two values by simply subtracting.
No special handling for overflow is neccessary.

Signed-off-by: Urs Thuermann <urs@isnogud.escape.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
candump.c

index a4e80d527c3f9e967c014b981c2b49f43d6fd2fa..a1146f55c8ad6aaabe93c6ac3a90a4fe6325ed18 100644 (file)
--- a/candump.c
+++ b/candump.c
@@ -674,12 +674,7 @@ int main(int argc, char **argv)
                                /* check for (unlikely) dropped frames on this specific socket */
                                if (dropcnt[i] != last_dropcnt[i]) {
 
-                                       __u32 frames;
-
-                                       if (dropcnt[i] > last_dropcnt[i])
-                                               frames = dropcnt[i] - last_dropcnt[i];
-                                       else
-                                               frames = UINT32_MAX - last_dropcnt[i] + dropcnt[i];
+                                       __u32 frames = dropcnt[i] - last_dropcnt[i];
 
                                        if (silent != SILENT_ON)
                                                printf("DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",