From 17a5fe602273e94d6622e0dfa47a67887c31f13d Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:08:10 -0700 Subject: [PATCH 1/7] clang-tidy: do not use else after return Found with readability-else-after-return Signed-off-by: Rosen Penev --- asc2log.c | 8 ++--- canfdtest.c | 42 +++++++++++----------- cangen.c | 4 +-- canlogserver.c | 5 ++- isotpdump.c | 98 +++++++++++++++++++++++++------------------------- isotpperf.c | 25 ++++++------- j1939acd.c | 5 ++- j1939cat.c | 13 +++---- lib.c | 2 +- libj1939.c | 8 ++--- 10 files changed, 101 insertions(+), 109 deletions(-) diff --git a/asc2log.c b/asc2log.c index cdfeb04..774949c 100644 --- a/asc2log.c +++ b/asc2log.c @@ -359,8 +359,7 @@ int get_date(struct timeval *tv, char *date) { before parsing the real year value (hack) */ if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms)) return 1; - else - sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); + sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); } } else { @@ -377,11 +376,10 @@ int get_date(struct timeval *tv, char *date) { before parsing the real year value (hack) */ if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms)) return 1; - else - sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); + sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs); } } - + //printf("h %d m %d s %d ms %03d d %d m %d y %d\n", //tms.tm_hour, tms.tm_min, tms.tm_sec, msecs, //tms.tm_mday, tms.tm_mon+1, tms.tm_year+1900); diff --git a/canfdtest.c b/canfdtest.c index 1a0f50a..241b3cc 100644 --- a/canfdtest.c +++ b/canfdtest.c @@ -181,20 +181,18 @@ static int send_frame(struct can_frame *frame) while ((ret = send(sockfd, frame, sizeof(*frame), 0)) != sizeof(*frame)) { - if (ret < 0) { - if (errno != ENOBUFS) { - perror("send failed"); - return -1; - } else { - if (verbose) { - printf("N"); - fflush(stdout); - } - } - } else { + if (ret >= 0) { fprintf(stderr, "send returned %d", ret); return -1; } + if (errno != ENOBUFS) { + perror("send failed"); + return -1; + } + if (verbose) { + printf("N"); + fflush(stdout); + } } return 0; } @@ -332,19 +330,19 @@ static int can_echo_gen(void) if (recv_tx_pos == inflight_count) recv_tx_pos = 0; continue; - } else { - if (!recv_tx[recv_rx_pos]) { - printf("RX before TX!\n"); - print_frame(&rx_frame, 0); - running = 0; - } - /* compare with expected */ - compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1); - recv_rx_pos++; - if (recv_rx_pos == inflight_count) - recv_rx_pos = 0; } + if (!recv_tx[recv_rx_pos]) { + printf("RX before TX!\n"); + print_frame(&rx_frame, 0); + running = 0; + } + /* compare with expected */ + compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1); + recv_rx_pos++; + if (recv_rx_pos == inflight_count) + recv_rx_pos = 0; + loops++; if (test_loops && loops >= test_loops) break; diff --git a/cangen.c b/cangen.c index e26c08b..7d0e82c 100644 --- a/cangen.c +++ b/cangen.c @@ -468,8 +468,8 @@ resend: if (poll(&fds, 1, polltimeout) < 0) { perror("poll"); return 1; - } else - goto resend; + } + goto resend; } else enobufs_count++; diff --git a/canlogserver.c b/canlogserver.c index ef338d1..8b61ac4 100644 --- a/canlogserver.c +++ b/canlogserver.c @@ -300,15 +300,14 @@ int main(int argc, char **argv) //printf("accepted\n"); if (!fork()) break; - else - close(accsocket); + close(accsocket); } else if (errno != EINTR) { perror("accept"); exit(1); } } - + for (i=0; i fflen) rcvlen = fflen; - + percent = (rcvlen * 100 / fflen); printf("\r %3lu%% ", percent); @@ -408,7 +410,6 @@ int main(int argc, char **argv) fflen = rcvlen = 0; } fflush(stdout); - } } close(s); diff --git a/j1939acd.c b/j1939acd.c index 35257fa..b11c6c4 100644 --- a/j1939acd.c +++ b/j1939acd.c @@ -383,10 +383,9 @@ static inline int addr_status_mine(int sa) { if (sa == s.current_sa) return '*'; - else if (addr[sa].flags & F_USE) + if (addr[sa].flags & F_USE) return '+'; - else - return '-'; + return '-'; } static void dump_status(void) diff --git a/j1939cat.c b/j1939cat.c index 81ffe04..c3a59b9 100644 --- a/j1939cat.c +++ b/j1939cat.c @@ -212,8 +212,7 @@ static int j1939cat_extract_serr(struct j1939cat_priv *priv) if (serr->ee_info == SCM_TSTAMP_SCHED) return -EINTR; - else - return 0; + return 0; case SO_EE_ORIGIN_LOCAL: /* * The serr->ee_origin == SO_EE_ORIGIN_LOCAL is @@ -319,11 +318,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf, ret = poll(&fds, 1, priv->polltimeout); if (ret == -EINTR) continue; - else if (ret < 0) + if (ret < 0) return -errno; - else if (!ret) + if (!ret) return -ETIME; - if (!(fds.revents & events)) { warn("%s: something else is wrong", __func__); return -EIO; @@ -333,11 +331,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf, ret = j1939cat_recv_err(priv); if (ret == -EINTR) continue; - else if (ret) + if (ret) return ret; - else if ((priv->repeat - 1) == stats->tskey) + if ((priv->repeat - 1) == stats->tskey) tx_done = true; - } if (fds.revents & POLLOUT) { diff --git a/lib.c b/lib.c index 097b2e8..4a9251f 100644 --- a/lib.c +++ b/lib.c @@ -588,7 +588,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c if (class & mask) { if (classes) n += snprintf(buf + n, len - n, "%s", sep); - n += snprintf(buf + n, len - n, "%s", error_classes[i]); + n += snprintf(buf + n, len - n, "%s", error_classes[i]); if (mask == CAN_ERR_LOSTARB) n += snprintf_error_lostarb(buf + n, len - n, cf); diff --git a/libj1939.c b/libj1939.c index 08e4fd7..072162d 100644 --- a/libj1939.c +++ b/libj1939.c @@ -64,8 +64,8 @@ static const char *libj1939_ifnam(int ifindex) */ libj1939_cleanup(); return libj1939_ifnam(ifindex); - } else - return NULL; + } + return NULL; } /* retrieve index */ @@ -88,8 +88,8 @@ static int libj1939_ifindex(const char *str) if (cached) { libj1939_cleanup(); return libj1939_ifindex(str); - } else - return 0; + } + return 0; } void libj1939_parse_canaddr(char *spec, struct sockaddr_can *paddr) From d5320d554edfcb359953418ff6bbd8afdb3d67b2 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:26:08 -0700 Subject: [PATCH 2/7] clang-tidy: fix wrong identation Found with readability-misleading-indentation Signed-off-by: Rosen Penev --- j1939acd.c | 48 ++++++++++++++------------- j1939cat.c | 79 +++++++++++++++++++++++---------------------- j1939spy.c | 48 ++++++++++++++------------- j1939sr.c | 42 ++++++++++++------------ testj1939.c | 93 +++++++++++++++++++++++++++-------------------------- 5 files changed, 159 insertions(+), 151 deletions(-) diff --git a/j1939acd.c b/j1939acd.c index b11c6c4..de09760 100644 --- a/j1939acd.c +++ b/j1939acd.c @@ -471,32 +471,34 @@ int main(int argc, char *argv[]) #endif /* argument parsing */ while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1) - switch (opt) { - case 'v': - ++s.verbose; - break; - case 'c': - s.cachefile = optarg; - break; - case 'r': - s.ranges = optarg; - break; - case 'a': - s.current_sa = strtoul(optarg, 0, 0); - break; - case 'p': + switch (opt) { + case 'v': + ++s.verbose; + break; + case 'c': + s.cachefile = optarg; + break; + case 'r': + s.ranges = optarg; + break; + case 'a': + s.current_sa = strtoul(optarg, 0, 0); + break; + case 'p': #ifdef _GNU_SOURCE - if (asprintf(&program_invocation_name, "%s.%s", program_invocation_short_name, optarg) < 0) - err(1, "asprintf(program invocation name)"); + if (asprintf(&program_invocation_name, "%s.%s", + program_invocation_short_name, optarg) < 0) + err(1, "asprintf(program invocation name)"); #else - err(0, "compile with -D_GNU_SOURCE to use -p"); + err(0, "compile with -D_GNU_SOURCE to use -p"); #endif - break; - default: - fputs(help_msg, stderr); - exit(1); - break; - } + break; + default: + fputs(help_msg, stderr); + exit(1); + break; + } + if (argv[optind]) s.name = strtoull(argv[optind++], 0, 16); if (argv[optind]) diff --git a/j1939cat.c b/j1939cat.c index c3a59b9..a672aa2 100644 --- a/j1939cat.c +++ b/j1939cat.c @@ -598,44 +598,47 @@ static int j1939cat_parse_args(struct j1939cat_priv *priv, int argc, char *argv[ /* argument parsing */ while ((opt = getopt(argc, argv, optstring)) != -1) - switch (opt) { - case 'i': - priv->infile = open(optarg, O_RDONLY); - if (priv->infile == -1) - err(EXIT_FAILURE, "can't open input file"); - priv->todo_filesize = 1; - break; - case 's': - priv->max_transfer = strtoul(optarg, NULL, 0); - if (priv->max_transfer > J1939_MAX_ETP_PACKET_SIZE) - err(EXIT_FAILURE, "used value (%zu) is bigger then allowed maximal size: %u.\n", - priv->max_transfer, J1939_MAX_ETP_PACKET_SIZE); - break; - case 'r': - priv->todo_recv = 1; - break; - case 'p': - priv->todo_prio = strtoul(optarg, NULL, 0); - break; - case 'P': - priv->polltimeout = strtoul(optarg, NULL, 0); - break; - case 'c': - priv->todo_connect = 1; - break; - case 'R': - priv->repeat = strtoul(optarg, NULL, 0); - if (priv->repeat < 1) - err(EXIT_FAILURE, "send/repeat count can't be less then 1\n"); - break; - case 'B': - priv->todo_broadcast = 1; - break; - case 'h': /*fallthrough*/ - default: - fputs(help_msg, stderr); - return EXIT_FAILURE; - } + switch (opt) { + case 'i': + priv->infile = open(optarg, O_RDONLY); + if (priv->infile == -1) + err(EXIT_FAILURE, "can't open input file"); + priv->todo_filesize = 1; + break; + case 's': + priv->max_transfer = strtoul(optarg, NULL, 0); + if (priv->max_transfer > J1939_MAX_ETP_PACKET_SIZE) + err(EXIT_FAILURE, + "used value (%zu) is bigger then allowed maximal size: %u.\n", + priv->max_transfer, + J1939_MAX_ETP_PACKET_SIZE); + break; + case 'r': + priv->todo_recv = 1; + break; + case 'p': + priv->todo_prio = strtoul(optarg, NULL, 0); + break; + case 'P': + priv->polltimeout = strtoul(optarg, NULL, 0); + break; + case 'c': + priv->todo_connect = 1; + break; + case 'R': + priv->repeat = strtoul(optarg, NULL, 0); + if (priv->repeat < 1) + err(EXIT_FAILURE, + "send/repeat count can't be less then 1\n"); + break; + case 'B': + priv->todo_broadcast = 1; + break; + case 'h': /*fallthrough*/ + default: + fputs(help_msg, stderr); + return EXIT_FAILURE; + } if (argv[optind]) { if (strcmp("-", argv[optind])) diff --git a/j1939spy.c b/j1939spy.c index 313d266..b676d43 100644 --- a/j1939spy.c +++ b/j1939spy.c @@ -107,30 +107,32 @@ int main(int argc, char **argv) /* argument parsing */ while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1) - switch (opt) { - case 'v': - ++s.verbose; - break; - case 'b': - s.pkt_len = strtoul(optarg, 0, 0); - break; - case 'P': - ++s.promisc; - break; - case 't': - if (optarg) { - if (!strchr("adzA", optarg[0])) - err(1, "unknown time option '%c'", optarg[0]); - s.time = optarg[0]; - } else { - s.time = 'z'; + switch (opt) { + case 'v': + ++s.verbose; + break; + case 'b': + s.pkt_len = strtoul(optarg, 0, 0); + break; + case 'P': + ++s.promisc; + break; + case 't': + if (optarg) { + if (!strchr("adzA", optarg[0])) + err(1, "unknown time option '%c'", + optarg[0]); + s.time = optarg[0]; + } else { + s.time = 'z'; + } + break; + default: + fputs(help_msg, stderr); + exit(1); + break; } - break; - default: - fputs(help_msg, stderr); - exit(1); - break; - } + if (argv[optind]) { optarg = argv[optind]; ret = libj1939_str2addr(optarg, 0, &s.addr); diff --git a/j1939sr.c b/j1939sr.c index 8c63f34..97a061a 100644 --- a/j1939sr.c +++ b/j1939sr.c @@ -99,27 +99,27 @@ int main(int argc, char **argv) #endif /* argument parsing */ while ((opt = getopt_long(argc, argv, optstring, long_opts, NULL)) != -1) - switch (opt) { - case 'v': - ++s.verbose; - break; - case 's': - s.pkt_len = strtoul(optarg, 0, 0); - if (!s.pkt_len) - err(1, "packet size of %s", optarg); - break; - case 'p': - s.priority = strtoul(optarg, 0, 0); - s.defined |= DEF_PRIO; - break; - case 'S': - s.sendflags |= MSG_SYN; - break; - default: - fputs(help_msg, stderr); - exit(1); - break; - } + switch (opt) { + case 'v': + ++s.verbose; + break; + case 's': + s.pkt_len = strtoul(optarg, 0, 0); + if (!s.pkt_len) + err(1, "packet size of %s", optarg); + break; + case 'p': + s.priority = strtoul(optarg, 0, 0); + s.defined |= DEF_PRIO; + break; + case 'S': + s.sendflags |= MSG_SYN; + break; + default: + fputs(help_msg, stderr); + exit(1); + break; + } if (argv[optind]) { optarg = argv[optind++]; diff --git a/testj1939.c b/testj1939.c index be9680f..09b4454 100644 --- a/testj1939.c +++ b/testj1939.c @@ -101,52 +101,53 @@ int main(int argc, char *argv[]) /* argument parsing */ while ((opt = getopt(argc, argv, optstring)) != -1) - switch (opt) { - case 'v': - verbose = 1; - break; - case 's': - todo_send = strtoul(optarg ?: "8", NULL, 0); - if (todo_send > sizeof(dat)) - err(1, "Unsupported size. max: %zu", sizeof(dat)); - break; - case 'r': - todo_recv = 1; - break; - case 'e': - todo_echo = 1; - break; - case 'p': - todo_prio = strtoul(optarg, NULL, 0); - break; - case 'P': - todo_promisc = 1; - break; - case 'c': - todo_connect = 1; - break; - case 'n': - todo_names = 1; - break; - case 'b': - todo_rebind = 1; - break; - case 'B': - todo_broadcast = 1; - break; - case 'o': - no_bind = 1; - break; - case 'w': - schedule_oneshot_itimer(strtod(optarg ?: "1", NULL)); - signal(SIGALRM, onsigalrm); - todo_wait = 1; - break; - default: - fputs(help_msg, stderr); - exit(1); - break; - } + switch (opt) { + case 'v': + verbose = 1; + break; + case 's': + todo_send = strtoul(optarg ?: "8", NULL, 0); + if (todo_send > sizeof(dat)) + err(1, "Unsupported size. max: %zu", + sizeof(dat)); + break; + case 'r': + todo_recv = 1; + break; + case 'e': + todo_echo = 1; + break; + case 'p': + todo_prio = strtoul(optarg, NULL, 0); + break; + case 'P': + todo_promisc = 1; + break; + case 'c': + todo_connect = 1; + break; + case 'n': + todo_names = 1; + break; + case 'b': + todo_rebind = 1; + break; + case 'B': + todo_broadcast = 1; + break; + case 'o': + no_bind = 1; + break; + case 'w': + schedule_oneshot_itimer(strtod(optarg ?: "1", NULL)); + signal(SIGALRM, onsigalrm); + todo_wait = 1; + break; + default: + fputs(help_msg, stderr); + exit(1); + break; + } if (argv[optind]) { if (strcmp("-", argv[optind])) From 3e67b5cbd1d2e0921d0251ccf3830aa715ee21ac Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:32:50 -0700 Subject: [PATCH 3/7] clang-tidy: remove pointless return Found with readability-redundant-control-flow Signed-off-by: Rosen Penev --- asc2log.c | 1 - 1 file changed, 1 deletion(-) diff --git a/asc2log.c b/asc2log.c index 774949c..8bbd6a7 100644 --- a/asc2log.c +++ b/asc2log.c @@ -335,7 +335,6 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace calc_tv(&tv, &read_tv, date_tvp, timestamps, dplace); prframe(outfile, &tv, interface, &cf, dlen, extra_info); fflush(outfile); - return; /* No support for really strange CANFD ErrorFrames format m( */ } From 33f3593436ea3eb4cc4c74b4a11538eb7be5a751 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:33:38 -0700 Subject: [PATCH 4/7] clang-tidy: use uppercase literal Found with readability-uppercase-literal-suffix Signed-off-by: Rosen Penev --- cangen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cangen.c b/cangen.c index 7d0e82c..0dfcb6e 100644 --- a/cangen.c +++ b/cangen.c @@ -297,7 +297,7 @@ int main(int argc, char **argv) } ts.tv_sec = gap / 1000; - ts.tv_nsec = (long)(((long long)(gap * 1000000)) % 1000000000ll); + ts.tv_nsec = (long)(((long long)(gap * 1000000)) % 1000000000LL); /* recognize obviously missing commandline option */ if (id_mode == MODE_FIX && frame.can_id > 0x7FF && !extended) { From 3e85fc5422536484b11742a7d82259fef90cb0fd Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:35:59 -0700 Subject: [PATCH 5/7] clang-tidy: fix cmp function usage Found with bugprone-suspicious-string-compare Signed-off-by: Rosen Penev --- can-calc-bit-timing.c | 3 ++- candump.c | 2 +- canlogserver.c | 5 ++--- canplayer.c | 2 +- cansniffer.c | 2 +- j1939cat.c | 4 ++-- testj1939.c | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/can-calc-bit-timing.c b/can-calc-bit-timing.c index 9129844..fff00f4 100644 --- a/can-calc-bit-timing.c +++ b/can-calc-bit-timing.c @@ -691,7 +691,8 @@ int main(int argc, char *argv[]) } for (i = 0; i < ARRAY_SIZE(can_calc_consts); i++) { - if (name && strcmp(can_calc_consts[i].bittiming_const.name, name)) + if (name && + strcmp(can_calc_consts[i].bittiming_const.name, name) != 0) continue; found = true; diff --git a/candump.c b/candump.c index 09d4770..b78f4fd 100644 --- a/candump.c +++ b/candump.c @@ -417,7 +417,7 @@ int main(int argc, char **argv) printf("using interface name '%s'.\n", ifr.ifr_name); #endif - if (strcmp(ANYDEV, ifr.ifr_name)) { + if (strcmp(ANYDEV, ifr.ifr_name) != 0) { if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); exit(1); diff --git a/canlogserver.c b/canlogserver.c index 8b61ac4..d67fa0f 100644 --- a/canlogserver.c +++ b/canlogserver.c @@ -356,15 +356,14 @@ int main(int argc, char **argv) addr.can_family = AF_CAN; - if (strcmp(ANYDEV, argv[optind+i])) { + if (strcmp(ANYDEV, argv[optind + i]) != 0) { strcpy(ifr.ifr_name, argv[optind+i]); if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); exit(1); } addr.can_ifindex = ifr.ifr_ifindex; - } - else + } else addr.can_ifindex = 0; /* any can interface */ if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) { diff --git a/canplayer.c b/canplayer.c index 9f2f438..b4b02af 100644 --- a/canplayer.c +++ b/canplayer.c @@ -215,7 +215,7 @@ int add_assignment(char *mode, int socket, char *txname, char *rxname, } strcpy(asgn[i].rxif, rxname); - if (strcmp(txname, "stdout")) { + if (strcmp(txname, "stdout") != 0) { strcpy(ifr.ifr_name, txname); if (ioctl(socket, SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); diff --git a/cansniffer.c b/cansniffer.c index 90d8d75..caa8796 100644 --- a/cansniffer.c +++ b/cansniffer.c @@ -333,7 +333,7 @@ int main(int argc, char **argv) addr.can_family = AF_CAN; - if (strcmp(ANYDEV, argv[optind])) + if (strcmp(ANYDEV, argv[optind]) != 0) addr.can_ifindex = if_nametoindex(argv[optind]); else addr.can_ifindex = 0; /* any can interface */ diff --git a/j1939cat.c b/j1939cat.c index a672aa2..160e329 100644 --- a/j1939cat.c +++ b/j1939cat.c @@ -641,13 +641,13 @@ static int j1939cat_parse_args(struct j1939cat_priv *priv, int argc, char *argv[ } if (argv[optind]) { - if (strcmp("-", argv[optind])) + if (strcmp("-", argv[optind]) != 0) libj1939_parse_canaddr(argv[optind], &priv->sockname); optind++; } if (argv[optind]) { - if (strcmp("-", argv[optind])) { + if (strcmp("-", argv[optind]) != 0) { libj1939_parse_canaddr(argv[optind], &priv->peername); priv->valid_peername = 1; } diff --git a/testj1939.c b/testj1939.c index 09b4454..c7af013 100644 --- a/testj1939.c +++ b/testj1939.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) } if (argv[optind]) { - if (strcmp("-", argv[optind])) + if (strcmp("-", argv[optind]) != 0) libj1939_parse_canaddr(argv[optind], &sockname); ++optind; } @@ -159,7 +159,7 @@ int main(int argc, char *argv[]) sockname.can_addr.j1939.addr++; if (argv[optind]) { - if (strcmp("-", argv[optind])) { + if (strcmp("-", argv[optind]) != 0) { libj1939_parse_canaddr(argv[optind], &peername); valid_peername = 1; } From b153fe3f3591c3320cb5ea7848f6ab94b3d1af2c Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:51:35 -0700 Subject: [PATCH 6/7] clang-tidy: sort includes alphabetically Found with llvm-include-order Signed-off-by: Rosen Penev --- asc2log.c | 8 ++++---- bcmserver.c | 16 ++++++++-------- can-calc-bit-timing.c | 4 ++-- canbusload.c | 16 ++++++++-------- candump.c | 18 +++++++++--------- canfdtest.c | 24 ++++++++++++------------ canframelen.c | 10 +++++----- cangen.c | 22 +++++++++++----------- cangw.c | 16 ++++++++-------- canlogserver.c | 24 ++++++++++++------------ canplayer.c | 12 ++++++------ cansniffer.c | 22 +++++++++++----------- isotpdump.c | 12 ++++++------ isotpperf.c | 10 +++++----- isotprecv.c | 8 ++++---- isotpsend.c | 8 ++++---- isotpserver.c | 18 +++++++++--------- isotpsniffer.c | 12 ++++++------ isotptun.c | 16 ++++++++-------- j1939acd.c | 20 ++++++++++---------- j1939cat.c | 4 ++-- j1939spy.c | 14 +++++++------- j1939sr.c | 14 +++++++------- lib.c | 4 ++-- libj1939.c | 8 ++++---- log2asc.c | 4 ++-- log2long.c | 2 +- slcan_attach.c | 14 +++++++------- slcand.c | 28 ++++++++++++++-------------- testj1939.c | 18 +++++++++--------- 30 files changed, 203 insertions(+), 203 deletions(-) diff --git a/asc2log.c b/asc2log.c index 8bbd6a7..9eb780c 100644 --- a/asc2log.c +++ b/asc2log.c @@ -42,18 +42,18 @@ * */ +#include +#include #include +#include #include #include #include -#include #include -#include -#include -#include #include #include +#include #include "lib.h" diff --git a/bcmserver.c b/bcmserver.c index 3fe092c..1f3ab82 100644 --- a/bcmserver.c +++ b/bcmserver.c @@ -108,21 +108,21 @@ * */ +#include +#include #include #include -#include #include -#include -#include #include +#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include #include #include diff --git a/can-calc-bit-timing.c b/can-calc-bit-timing.c index fff00f4..9f1601f 100644 --- a/can-calc-bit-timing.c +++ b/can-calc-bit-timing.c @@ -18,16 +18,16 @@ #include #include +#include #include #include #include #include #include -#include #include -#include #include +#include /* imported from kernel */ diff --git a/canbusload.c b/canbusload.c index ff07b60..d6bfd78 100644 --- a/canbusload.c +++ b/canbusload.c @@ -42,21 +42,21 @@ * */ -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include +#include +#include +#include +#include #include #include -#include -#include #include -#include #include #include diff --git a/candump.c b/candump.c index b78f4fd..41f680c 100644 --- a/candump.c +++ b/candump.c @@ -42,23 +42,23 @@ * */ +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include #include -#include +#include +#include +#include +#include #include #include -#include -#include #include -#include #include #include diff --git a/canfdtest.c b/canfdtest.c index 241b3cc..9ee0d3c 100644 --- a/canfdtest.c +++ b/canfdtest.c @@ -17,24 +17,24 @@ * Send feedback to */ +#include +#include +#include +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include #include -#include -#include -#include -#include +#include -#include -#include -#include -#include #include +#include +#include +#include +#include #include #include diff --git a/canframelen.c b/canframelen.c index 3c5453f..6ce3c4d 100644 --- a/canframelen.c +++ b/canframelen.c @@ -45,12 +45,12 @@ */ #include "canframelen.h" -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include /** * Functions and types for CRC checks. diff --git a/cangen.c b/cangen.c index 0dfcb6e..3641986 100644 --- a/cangen.c +++ b/cangen.c @@ -42,28 +42,28 @@ * */ +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include #include #include -#include -#include #include -#include +#include "lib.h" #include #include -#include "lib.h" #define DEFAULT_GAP 200 /* ms */ #define DEFAULT_BURST_COUNT 1 diff --git a/cangw.c b/cangw.c index 715a44f..52310c9 100644 --- a/cangw.c +++ b/cangw.c @@ -42,17 +42,17 @@ * */ -#include -#include -#include -#include -#include #include -#include -#include +#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include enum { UNSPEC, diff --git a/canlogserver.c b/canlogserver.c index d67fa0f..5619a9c 100644 --- a/canlogserver.c +++ b/canlogserver.c @@ -42,29 +42,29 @@ * */ -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include +#include -#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include #include "lib.h" diff --git a/canplayer.c b/canplayer.c index b4b02af..1cf420c 100644 --- a/canplayer.c +++ b/canplayer.c @@ -42,19 +42,19 @@ * */ +#include #include +#include #include #include -#include -#include #include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include "lib.h" diff --git a/cansniffer.c b/cansniffer.c index caa8796..4e1725a 100644 --- a/cansniffer.c +++ b/cansniffer.c @@ -42,25 +42,25 @@ * */ +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #include #include -#include -#include -#include #include -#include #include #include diff --git a/isotpdump.c b/isotpdump.c index c18dc5a..416ede7 100644 --- a/isotpdump.c +++ b/isotpdump.c @@ -42,23 +42,23 @@ * */ +#include #include #include -#include #include -#include -#include #include +#include +#include #include -#include -#include #include +#include +#include +#include "terminal.h" #include #include #include -#include "terminal.h" #define NO_CAN_ID 0xFFFFFFFFU diff --git a/isotpperf.c b/isotpperf.c index 19fb4e6..d2cd3e0 100644 --- a/isotpperf.c +++ b/isotpperf.c @@ -42,18 +42,18 @@ * */ +#include +#include #include #include -#include -#include #include -#include #include +#include #include -#include -#include #include +#include +#include #include #include diff --git a/isotprecv.c b/isotprecv.c index c4b8e04..406cf5d 100644 --- a/isotprecv.c +++ b/isotprecv.c @@ -42,16 +42,16 @@ * */ +#include #include -#include #include #include -#include +#include #include -#include -#include #include +#include +#include #include #include diff --git a/isotpsend.c b/isotpsend.c index 3797e95..01572c9 100644 --- a/isotpsend.c +++ b/isotpsend.c @@ -42,16 +42,16 @@ * */ +#include #include -#include #include #include -#include +#include #include -#include -#include #include +#include +#include #include #include diff --git a/isotpserver.c b/isotpserver.c index 946169e..691df48 100644 --- a/isotpserver.c +++ b/isotpserver.c @@ -57,22 +57,22 @@ * */ +#include +#include +#include #include #include -#include -#include #include -#include -#include #include +#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include #include #include diff --git a/isotpsniffer.c b/isotpsniffer.c index 3a022f1..a06ecef 100644 --- a/isotpsniffer.c +++ b/isotpsniffer.c @@ -42,23 +42,23 @@ * */ -#include -#include #include +#include +#include #include #include -#include #include +#include #include -#include -#include #include +#include +#include +#include "terminal.h" #include #include #include -#include "terminal.h" #define NO_CAN_ID 0xFFFFFFFFU diff --git a/isotptun.c b/isotptun.c index cb40ecc..a471025 100644 --- a/isotptun.c +++ b/isotptun.c @@ -48,21 +48,21 @@ * */ -#include -#include -#include -#include -#include -#include #include +#include +#include #include #include +#include +#include +#include #include +#include #include -#include -#include #include +#include +#include #include #include diff --git a/j1939acd.c b/j1939acd.c index de09760..2869d0a 100644 --- a/j1939acd.c +++ b/j1939acd.c @@ -10,22 +10,22 @@ * as published by the Free Software Foundation */ -#include -#include -#include #include -#include -#include +#include +#include #include +#include +#include +#include -#include -#include #include -#include -#include -#include +#include #include #include +#include +#include +#include +#include #include "libj1939.h" diff --git a/j1939cat.c b/j1939cat.c index 160e329..e6f4205 100644 --- a/j1939cat.c +++ b/j1939cat.c @@ -8,16 +8,16 @@ #include #include #include +#include #include #include #include #include #include -#include #include -#include #include +#include #include #include "libj1939.h" diff --git a/j1939spy.c b/j1939spy.c index b676d43..e49ed14 100644 --- a/j1939spy.c +++ b/j1939spy.c @@ -10,19 +10,19 @@ * as published by the Free Software Foundation */ -#include -#include -#include -#include #include #include +#include +#include +#include +#include -#include -#include #include -#include +#include #include +#include #include +#include #include "libj1939.h" diff --git a/j1939sr.c b/j1939sr.c index 97a061a..cdf6da5 100644 --- a/j1939sr.c +++ b/j1939sr.c @@ -10,20 +10,20 @@ * as published by the Free Software Foundation */ -#include -#include -#include #include #include +#include +#include +#include -#include -#include #include +#include #include -#include -#include #include +#include #include +#include +#include #include "libj1939.h" diff --git a/lib.c b/lib.c index 4a9251f..38a79ca 100644 --- a/lib.c +++ b/lib.c @@ -42,13 +42,13 @@ * */ +#include #include #include -#include -#include /* for sa_family_t */ #include #include +#include /* for sa_family_t */ #include "lib.h" diff --git a/libj1939.c b/libj1939.c index 072162d..506b525 100644 --- a/libj1939.c +++ b/libj1939.c @@ -10,16 +10,16 @@ * as published by the Free Software Foundation */ -#include -#include -#include #include #include +#include +#include +#include -#include #include #include #include +#include #include diff --git a/log2asc.c b/log2asc.c index 49e8753..e2f9c6a 100644 --- a/log2asc.c +++ b/log2asc.c @@ -42,15 +42,15 @@ * */ +#include #include #include #include -#include #include +#include #include #include -#include #include "lib.h" diff --git a/log2long.c b/log2long.c index 2033d2c..25814e2 100644 --- a/log2long.c +++ b/log2long.c @@ -44,8 +44,8 @@ #include -#include #include +#include #include "lib.h" diff --git a/slcan_attach.c b/slcan_attach.c index 6fa9269..a022252 100644 --- a/slcan_attach.c +++ b/slcan_attach.c @@ -42,18 +42,18 @@ * */ +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include #include -#include +#include #include -#include -#include +#include void print_usage(char *prg) { diff --git a/slcand.c b/slcand.c index 72e7ed4..4a15697 100644 --- a/slcand.c +++ b/slcand.c @@ -22,25 +22,25 @@ * */ +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include +#include /* Change this to whatever your daemon is called */ #define DAEMON_NAME "slcand" diff --git a/testj1939.c b/testj1939.c index c7af013..330e88c 100644 --- a/testj1939.c +++ b/testj1939.c @@ -10,20 +10,20 @@ * as published by the Free Software Foundation */ -#include -#include -#include #include -#include -#include +#include +#include #include +#include +#include +#include -#include -#include #include -#include -#include +#include #include +#include +#include +#include #include "libj1939.h" From 48bb69bc7bcb1b8ff6ad17a647c888034a56199b Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 12 Oct 2020 00:57:06 -0700 Subject: [PATCH 7/7] remove basic usages of memset with {} Signed-off-by: Rosen Penev --- asc2log.c | 4 +--- cangw.c | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/asc2log.c b/asc2log.c index 9eb780c..b2219c9 100644 --- a/asc2log.c +++ b/asc2log.c @@ -224,7 +224,7 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace int interface; static struct timeval tv; /* current frame timestamp */ static struct timeval read_tv; /* frame timestamp from ASC file */ - struct canfd_frame cf; + struct canfd_frame cf = {}; unsigned char brs, esi, ctmp; unsigned int flags; int dlc, dlen = 0; @@ -241,8 +241,6 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 c0 \ 100000 214 223040 80000000 46500250 460a0250 20011736 20010205 */ - memset(&cf, 0, sizeof(cf)); - /* check for valid line without symbolic name */ if (sscanf(buf, "%lu.%lu %*s %d %2s %s %hhx %hhx %x %d ", &read_tv.tv_sec, &read_tv.tv_usec, &interface, diff --git a/cangw.c b/cangw.c index 52310c9..0485365 100644 --- a/cangw.c +++ b/cangw.c @@ -706,8 +706,8 @@ int main(int argc, char **argv) struct can_filter filter; struct sockaddr_nl nladdr; - struct cgw_csum_xor cs_xor; - struct cgw_csum_crc8 cs_crc8; + struct cgw_csum_xor cs_xor = {}; + struct cgw_csum_crc8 cs_crc8 = {}; char crc8tab[513] = {0}; struct modattr modmsg[CGW_MOD_FUNCS]; @@ -717,8 +717,6 @@ int main(int argc, char **argv) int i; memset(&req, 0, sizeof(req)); - memset(&cs_xor, 0, sizeof(cs_xor)); - memset(&cs_crc8, 0, sizeof(cs_crc8)); while ((opt = getopt(argc, argv, "ADFLs:d:Xteiu:l:f:c:p:x:m:M:?")) != -1) { switch (opt) {