]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - candump.c
candump: fix off-by-one error in dropcount calculation
[can-utils.git] / candump.c
index c865bd76f9dd78f41b99bbdae31b1067ab411809..a1146f55c8ad6aaabe93c6ac3a90a4fe6325ed18 100644 (file)
--- a/candump.c
+++ b/candump.c
@@ -43,6 +43,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <string.h>
 #include <signal.h>
@@ -673,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 = 4294967295U - last_dropcnt[i] + dropcnt[i]; /* 4294967295U == UINT32_MAX */
+                                       __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",
@@ -698,18 +694,23 @@ int main(int argc, char **argv)
                                        view |= CANLIB_VIEW_INDENT_SFF;
 
                                if (log) {
+                                       char buf[CL_CFSZ]; /* max length */
+
                                        /* log CAN frame with absolute timestamp & device */
-                                       fprintf(logfile, "(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
-                                       fprintf(logfile, "%*s ", max_devname_len, devname[idx]);
-                                       /* without separator as logfile use-case is parsing */
-                                       fprint_canframe(logfile, &frame, "\n", 0, maxdlen);
+                                       sprint_canframe(buf, &frame, 0, maxdlen);
+                                       fprintf(logfile, "(%010ld.%06ld) %*s %s\n",
+                                               tv.tv_sec, tv.tv_usec,
+                                               max_devname_len, devname[idx], buf);
                                }
 
                                if (logfrmt) {
+                                       char buf[CL_CFSZ]; /* max length */
+
                                        /* print CAN frame in log file style to stdout */
-                                       printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
-                                       printf("%*s ", max_devname_len, devname[idx]);
-                                       fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
+                                       sprint_canframe(buf, &frame, 0, maxdlen);
+                                       printf("(%010ld.%06ld) %*s %s\n",
+                                              tv.tv_sec, tv.tv_usec,
+                                              max_devname_len, devname[idx], buf);
                                        goto out_fflush; /* no other output to stdout */
                                }