From 0c61f2ac4c692c4bdbd7ce2e0375a5634333a9c1 Mon Sep 17 00:00:00 2001 From: Urs Thuermann Date: Thu, 23 Oct 2014 19:23:00 +0200 Subject: [PATCH 1/1] candump: fix off-by-one error in dropcount calculation 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 Signed-off-by: Oliver Hartkopp --- candump.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/candump.c b/candump.c index a4e80d5..a1146f5 100644 --- 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", -- 2.39.2