From: Donald Sharp Date: Mon, 18 Jun 2018 19:23:49 +0000 (-0400) Subject: Merge pull request #2486 from pacovn/cppcheck_fmt_validation X-Git-Tag: frr-6.1-dev~305 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=6f32955ec309b050906d1ed8006a4cae74118c74;hp=2daa80f0c078b8d5e8f992fe3d206f75238ae075;p=mirror_frr.git Merge pull request #2486 from pacovn/cppcheck_fmt_validation babeld, lib, ospfd, tests: fmt fixes (cppcheck) --- diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index d4958ddf2..453fd8e04 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -1001,7 +1001,7 @@ show_babel_routes_sub(struct babel_route *route, struct vty *vty, break; if(k > 0) channels[j++] = ','; - snprintf(channels + j, 100 - j, "%d", route->channels[k]); + snprintf(channels + j, 100 - j, "%u", route->channels[k]); j = strlen(channels); } snprintf(channels + j, 100 - j, ")"); diff --git a/babeld/util.c b/babeld/util.c index 7dff11d12..4a3ecace0 100644 --- a/babeld/util.c +++ b/babeld/util.c @@ -303,7 +303,7 @@ format_thousands(unsigned int value) static char buf[4][15]; static int i = 0; i = (i + 1) % 4; - snprintf(buf[i], 15, "%d.%.3d", value / 1000, value % 1000); + snprintf(buf[i], 15, "%u.%.3u", value / 1000, value % 1000); return buf[i]; } diff --git a/lib/csv.c b/lib/csv.c index e6a5eae2e..ce84783aa 100644 --- a/lib/csv.c +++ b/lib/csv.c @@ -663,8 +663,8 @@ int main() log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_init(&csv, buf, 256); - sprintf(hdr1, "%4u", 0); - sprintf(hdr2, "%4u", 1); + sprintf(hdr1, "%4d", 0); + sprintf(hdr2, "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode(&csv, 2, hdr1, hdr2); @@ -676,8 +676,8 @@ int main() } csv_encode(&csv, 2, "pdfadfadfadsadsaddfdfdsfdsd", "35444554545454545"); log_verbose("%s\n", buf); - sprintf(hdr1, "%4u", csv.csv_len); - sprintf(hdr2, "%4u", 1); + sprintf(hdr1, "%4d", csv.csv_len); + sprintf(hdr2, "%4d", 1); log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode_record(&csv, rec, 2, hdr1, hdr2); diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index fea5a8cc4..69fd61e2a 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -60,10 +60,10 @@ static csv_record_t *_ptm_lib_encode_header(csv_t *csv, csv_record_t *rec, char client_buf[32]; csv_record_t *rec1; - sprintf(msglen_buf, "%4u", msglen); - sprintf(vers_buf, "%4u", version); - sprintf(type_buf, "%4u", type); - sprintf(cmdid_buf, "%4u", cmd_id); + sprintf(msglen_buf, "%4d", msglen); + sprintf(vers_buf, "%4d", version); + sprintf(type_buf, "%4d", type); + sprintf(cmdid_buf, "%4d", cmd_id); snprintf(client_buf, 17, "%16.16s", client_name); if (rec) { rec1 = csv_encode_record(csv, rec, 5, msglen_buf, vers_buf, diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index 1c911ebef..d8742943c 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -199,17 +199,17 @@ const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size) } if (w > 99) - snprintf(buf, size, "%ldw%1ldd", w, d); + snprintf(buf, size, "%luw%1lud", w, d); else if (w) - snprintf(buf, size, "%ldw%1ldd%02ldh", w, d, h); + snprintf(buf, size, "%luw%1lud%02luh", w, d, h); else if (d) - snprintf(buf, size, "%1ldd%02ldh%02ldm", d, h, m); + snprintf(buf, size, "%1lud%02luh%02lum", d, h, m); else if (h) - snprintf(buf, size, "%ldh%02ldm%02lds", h, m, (long)t->tv_sec); + snprintf(buf, size, "%luh%02lum%02lds", h, m, (long)t->tv_sec); else if (m) - snprintf(buf, size, "%ldm%02lds", m, (long)t->tv_sec); + snprintf(buf, size, "%lum%02lds", m, (long)t->tv_sec); else if (ms) - snprintf(buf, size, "%ld.%03lds", (long)t->tv_sec, ms); + snprintf(buf, size, "%ld.%03lus", (long)t->tv_sec, ms); else snprintf(buf, size, "%ld usecs", (long)t->tv_usec); @@ -1683,7 +1683,7 @@ static int config_write_debug(struct vty *vty) return CMD_SUCCESS; if (ospf->instance) - sprintf(str, " %d", ospf->instance); + sprintf(str, " %u", ospf->instance); /* debug ospf ism (status|events|timers). */ if (IS_CONF_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM) diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index ea31d8c2c..23353b3c3 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -857,7 +857,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, "ospf_vl_new(): creating pseudo zebra interface vrf id %u", ospf->vrf_id); - snprintf(ifname, sizeof(ifname), "VLINK%d", vlink_count); + snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count); vi = if_create(ifname, ospf->vrf_id); /* * if_create sets ZEBRA_INTERFACE_LINKDETECTION diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c index 3972f7676..13d35b0e9 100644 --- a/tests/lib/test_checksum.c +++ b/tests/lib/test_checksum.c @@ -506,7 +506,7 @@ int main(int argc, char **argv) printf("verify: lib failed\n"); if (ospfd != lib) { - printf("Mismatch in values at size %u\n" + printf("Mismatch in values at size %d\n" "ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" "lib: 0x%04x\n", diff --git a/tests/lib/test_graph.c b/tests/lib/test_graph.c index f21f8b793..2801c48bc 100644 --- a/tests/lib/test_graph.c +++ b/tests/lib/test_graph.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) /* create vertices */ for (unsigned int i = 0; i < NUMNODES; i++) { - snprintf(names[i], sizeof(names[i]), "%d", i); + snprintf(names[i], sizeof(names[i]), "%u", i); gn[i] = graph_new_node(g, names[i], NULL); } diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c index f9a244e25..d5f4badc8 100644 --- a/tests/lib/test_timer_performance.c +++ b/tests/lib/test_timer_performance.c @@ -92,9 +92,9 @@ int main(int argc, char **argv) t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec); t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000; - printf("Scheduling %d random timers took %ld.%03ld seconds.\n", + printf("Scheduling %d random timers took %lu.%03lu seconds.\n", SCHEDULE_TIMERS, t_schedule / 1000, t_schedule % 1000); - printf("Removing %d random timers took %ld.%03ld seconds.\n", + printf("Removing %d random timers took %lu.%03lu seconds.\n", REMOVE_TIMERS, t_remove / 1000, t_remove % 1000); fflush(stdout);