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 <urs@isnogud.escape.de> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/1/head
parent
9c5bfab229
commit
0c61f2ac4c
|
|
@ -674,12 +674,7 @@ int main(int argc, char **argv)
|
||||||
/* check for (unlikely) dropped frames on this specific socket */
|
/* check for (unlikely) dropped frames on this specific socket */
|
||||||
if (dropcnt[i] != last_dropcnt[i]) {
|
if (dropcnt[i] != last_dropcnt[i]) {
|
||||||
|
|
||||||
__u32 frames;
|
__u32 frames = dropcnt[i] - last_dropcnt[i];
|
||||||
|
|
||||||
if (dropcnt[i] > last_dropcnt[i])
|
|
||||||
frames = dropcnt[i] - last_dropcnt[i];
|
|
||||||
else
|
|
||||||
frames = UINT32_MAX - last_dropcnt[i] + dropcnt[i];
|
|
||||||
|
|
||||||
if (silent != SILENT_ON)
|
if (silent != SILENT_ON)
|
||||||
printf("DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",
|
printf("DROPCOUNT: dropped %d CAN frame%s on '%s' socket (total drops %d)\n",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue