From e0b3a8b5a2e38f35bb957cedc530ae184c26d912 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 12 Apr 2022 08:37:22 +0200 Subject: [PATCH] BUILD: halog: fix some incorrect signs in printf formats for integers In issue #1184, cppcheck found several issues in the printf formats used to display integers, some of which are unsigned but which used to still rely on "%d". --- admin/halog/fgets2.c | 2 +- admin/halog/halog.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/admin/halog/fgets2.c b/admin/halog/fgets2.c index 62f1070942..7fbe16bb69 100644 --- a/admin/halog/fgets2.c +++ b/admin/halog/fgets2.c @@ -261,7 +261,7 @@ int main() { while ((p=fgets2(stdin))) lines++; - printf("lines=%d\n", lines); + printf("lines=%u\n", lines); return 0; } #endif diff --git a/admin/halog/halog.c b/admin/halog/halog.c index 8012c48b5b..45eec7576b 100644 --- a/admin/halog/halog.c +++ b/admin/halog/halog.c @@ -207,7 +207,7 @@ void help() " -uao, -uto: average times computed on valid ('OK') requests\n" " -uba, -ubt: average bytes returned, total bytes returned\n" " -hdr output captured header at the given :\n", - SOURCE_FIELD,SOURCE_FIELD + (int)SOURCE_FIELD, (int)SOURCE_FIELD ); exit(0); } @@ -1150,7 +1150,7 @@ int main(int argc, char **argv) ms = h % 1000; h = h / 1000; s = h % 60; h = h / 60; m = h % 60; h = h / 60; - printf("%02d:%02d:%02d.%03d %d %d %d\n", h, m, s, ms, last, d, t->count); + printf("%02u:%02u:%02u.%03u %d %u %u\n", h, m, s, ms, last, d, t->count); lines_out++; if (lines_max >= 0 && lines_out >= lines_max) break; @@ -1208,7 +1208,7 @@ int main(int argc, char **argv) for (step = 1; step <= 1000;) { unsigned int thres = lines_out * (step / 1000.0); - printf("%3.1f %d ", step/10.0, thres); + printf("%3.1f %u ", step/10.0, thres); for (f = 1; f < 5; f++) { struct eb32_node *next; while (cum[f] < thres) { @@ -1237,7 +1237,7 @@ int main(int argc, char **argv) n = eb32_first(&timers[0]); while (n) { t = container_of(n, struct timer, node); - printf("%d %d\n", n->key, t->count); + printf("%d %u\n", n->key, t->count); lines_out++; if (lines_max >= 0 && lines_out >= lines_max) break; @@ -1260,7 +1260,7 @@ int main(int argc, char **argv) for (f = 0; f <= 5; f++) tot_rq += srv->st_cnt[f]; - printf("%s %d %d %d %d %d %d %d %d %.1f %d %d\n", + printf("%s %u %u %u %u %u %u %d %u %.1f %d %d\n", srv_node->key, srv->st_cnt[1], srv->st_cnt[2], srv->st_cnt[3], srv->st_cnt[4], srv->st_cnt[5], srv->st_cnt[0], tot_rq, @@ -1277,7 +1277,7 @@ int main(int argc, char **argv) n = eb32_first(&timers[0]); while (n) { t = container_of(n, struct timer, node); - printf("%c%c %d\n", (n->key >> 8), (n->key) & 255, t->count); + printf("%c%c %u\n", (n->key >> 8), (n->key) & 255, t->count); lines_out++; if (lines_max >= 0 && lines_out >= lines_max) break; @@ -1333,7 +1333,7 @@ int main(int argc, char **argv) node = eb_last(&timers[0]); while (node) { ustat = container_of(node, struct url_stat, node.url.node); - printf("%d %d %llu %llu %llu %llu %llu %llu %s\n", + printf("%u %u %llu %llu %llu %llu %llu %llu %s\n", ustat->nb_req, ustat->nb_err, ustat->total_time,