]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: halog: fix some incorrect signs in printf formats for integers
authorWilly Tarreau <w@1wt.eu>
Tue, 12 Apr 2022 06:37:22 +0000 (08:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 12 Apr 2022 06:40:38 +0000 (08:40 +0200)
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
admin/halog/halog.c

index 62f10709427df20ea8926f63e31099ac940a587c..7fbe16bb69e907de9ec902993d14ce90d8640bd0 100644 (file)
@@ -261,7 +261,7 @@ int main() {
 
        while ((p=fgets2(stdin)))
                lines++;
-       printf("lines=%d\n", lines);
+       printf("lines=%u\n", lines);
        return 0;
 }
 #endif
index 8012c48b5b08982ae2fa6e3f754c54e8c83dd7f4..45eec7576b55a4f04d81d1d0732ae1062478cff8 100644 (file)
@@ -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 <block>:<field>\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,