]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Fix field width specifier warnings
authorJan Janssen <medhefgo@web.de>
Tue, 30 Aug 2022 07:52:03 +0000 (09:52 +0200)
committerJan Janssen <medhefgo@web.de>
Tue, 30 Aug 2022 10:03:33 +0000 (12:03 +0200)
The casting here isn't pretty, but at least it makes it obvious what is
happening instead of implicit and it allows enabling -Wformat-signedness.

src/cgtop/cgtop.c
src/firstboot/firstboot.c
src/libsystemd/sd-bus/bus-match.c
src/libsystemd/sd-journal/test-journal-send.c
src/resolve/resolvectl.c
src/shared/cgroup-show.c
src/shared/logs-show.c
src/test/test-random-util.c

index 46f4624048d1f2cec85fd021f0a75c3b4640ea0b..95c39875256c71b5c8b8106fa27188f73dbd495c 100644 (file)
@@ -631,7 +631,7 @@ static void display(Hashmap *a) {
 
         if (on_tty()) {
                 const char *on, *off;
-                unsigned cpu_len = arg_cpu_type == CPU_PERCENT ? 6 : maxtcpu;
+                int cpu_len = arg_cpu_type == CPU_PERCENT ? 6 : maxtcpu;
 
                 path_columns = columns() - 36 - cpu_len;
                 if (path_columns < 10)
@@ -685,7 +685,9 @@ static void display(Hashmap *a) {
                         else
                                 fputs("      -", stdout);
                 } else
-                        printf(" %*s", maxtcpu, MAYBE_FORMAT_TIMESPAN((usec_t) (g->cpu_usage / NSEC_PER_USEC), 0));
+                        printf(" %*s",
+                               (int) maxtcpu,
+                               MAYBE_FORMAT_TIMESPAN((usec_t) (g->cpu_usage / NSEC_PER_USEC), 0));
 
                 printf(" %8s", MAYBE_FORMAT_BYTES(g->memory_valid, g->memory));
                 printf(" %8s", MAYBE_FORMAT_BYTES(g->io_valid, g->io_input_bps));
index fd9954b54d4f52452722112f01c1126569da8819..abeafacc3870e9ddadb071bad67a4c2d018aec19 100644 (file)
@@ -161,7 +161,7 @@ static int show_menu(char **x, unsigned n_columns, unsigned width, unsigned perc
                         if (!e)
                                 return log_oom();
 
-                        printf("%4zu) %-*s", j * per_column + i + 1, width, e);
+                        printf("%4zu) %-*s", j * per_column + i + 1, (int) width, e);
                 }
 
                 putchar('\n');
index d4da60717eba00fd3a5000f1e83083c957848ed7..157c660fe9b24254d21fceb4cb8139bc93ac605e 100644 (file)
@@ -1013,7 +1013,7 @@ void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) {
         if (!node)
                 return;
 
-        fprintf(out, "%*s[%s]", 2 * level, "", bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
+        fprintf(out, "%*s[%s]", 2 * (int) level, "", bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
 
         if (node->type == BUS_MATCH_VALUE) {
                 if (node->parent->type == BUS_MATCH_MESSAGE_TYPE)
index 8f9d9c4a30cfead42647d53acee824eeb11ffbaa..ca1fe7c303055e645cf712a758fbb36142c00156 100644 (file)
@@ -16,8 +16,8 @@ TEST(journal_print) {
         assert_se(sd_journal_print(LOG_INFO, "XXX") == 0);
         assert_se(sd_journal_print(LOG_INFO, "%s", "YYY") == 0);
         assert_se(sd_journal_print(LOG_INFO, "X%4094sY", "ZZZ") == 0);
-        assert_se(sd_journal_print(LOG_INFO, "X%*sY", LONG_LINE_MAX - 8 - 3, "ZZZ") == 0);
-        assert_se(sd_journal_print(LOG_INFO, "X%*sY", LONG_LINE_MAX - 8 - 2, "ZZZ") == -ENOBUFS);
+        assert_se(sd_journal_print(LOG_INFO, "X%*sY", (int) LONG_LINE_MAX - 8 - 3, "ZZZ") == 0);
+        assert_se(sd_journal_print(LOG_INFO, "X%*sY", (int) LONG_LINE_MAX - 8 - 2, "ZZZ") == -ENOBUFS);
 }
 
 TEST(journal_send) {
index 8e6620d6044d992037bff68b25a6f8202a109ac4..677e77b0818f7c3560853a4021bad24c1dc64d63 100644 (file)
@@ -1396,7 +1396,7 @@ static int status_print_strv_ifindex(int ifindex, const char *ifname, char **p)
                         printf(" %s", *i);
                         position = size_add(size_add(position, 1), our_len);
                 } else {
-                        printf("\n%*s%s", indent, "", *i);
+                        printf("\n%*s%s", (int) indent, "", *i);
                         position = size_add(our_len, indent);
                 }
         }
index f3f97f6cacfb193921803802291be28e00e28559..ca96e198f316951dcd1b5ac5dc6512fafdcfb3bf 100644 (file)
@@ -74,7 +74,7 @@ static void show_pid_array(
                 else
                         printf("%s%s", prefix, special_glyph(((more || i < n_pids-1) ? SPECIAL_GLYPH_TREE_BRANCH : SPECIAL_GLYPH_TREE_RIGHT)));
 
-                printf("%s%*"PID_PRI" %s%s\n", ansi_grey(), pid_width, pids[i], strna(t), ansi_normal());
+                printf("%s%*"PID_PRI" %s%s\n", ansi_grey(), (int) pid_width, pids[i], strna(t), ansi_normal());
         }
 }
 
index 5e2fd580dbb197e44ad657f8df1ba0c57c53c056..98219e14fa2eb727e3271dfdae3c7d202c2005be 100644 (file)
@@ -242,9 +242,8 @@ static bool print_multiline(
         for (pos = message;
              pos < message + message_len;
              pos = end + 1, line++) {
-                bool continuation = line > 0;
                 bool tail_line;
-                int len;
+                int len, indent = (line > 0) * prefix;
                 for (end = pos; end < message + message_len && *end != '\n'; end++)
                         ;
                 len = end - pos;
@@ -266,7 +265,7 @@ static bool print_multiline(
                             highlight[0] < (size_t) len) {
 
                                 fprintf(f, "%*s%s%.*s",
-                                        continuation * prefix, "",
+                                        indent, "",
                                         color_on, (int) highlight[0], pos);
                                 fprintf(f, "%s%.*s",
                                         highlight_on,
@@ -281,7 +280,7 @@ static bool print_multiline(
 
                         } else
                                 fprintf(f, "%*s%s%.*s%s\n",
-                                        continuation * prefix, "",
+                                        indent, "",
                                         color_on, len, pos, color_off);
                         continue;
                 }
@@ -292,7 +291,7 @@ static bool print_multiline(
                 if (prefix < n_columns && n_columns - prefix >= 3) {
                         if (n_columns - prefix > (unsigned) len + 3)
                                 fprintf(f, "%*s%s%.*s...%s\n",
-                                        continuation * prefix, "",
+                                        indent, "",
                                         color_on, len, pos, color_off);
                         else {
                                 _cleanup_free_ char *e = NULL;
@@ -301,11 +300,11 @@ static bool print_multiline(
                                                   tail_line ? 100 : 90);
                                 if (!e)
                                         fprintf(f, "%*s%s%.*s%s\n",
-                                                continuation * prefix, "",
+                                                indent, "",
                                                 color_on, len, pos, color_off);
                                 else
                                         fprintf(f, "%*s%s%s%s\n",
-                                                continuation * prefix, "",
+                                                indent, "",
                                                 color_on, e, color_off);
                         }
                 } else
index 3128f669b7781c783f2205d74573f7844c6143d0..e5972718b46ff5e9e9a037f7571b57183981f711 100644 (file)
@@ -63,7 +63,7 @@ static void test_random_u64_range_one(unsigned mod) {
                 double dev = (count[i] - exp) / sqrt(exp * (mod > 1 ? mod - 1 : 1) / mod);
                 log_debug("%02zu: %5u (%+.3f)%*s",
                           i, count[i], dev,
-                          count[i] / scale, "x");
+                          (int) (count[i] / scale), "x");
 
                 assert_se(fabs(dev) < 6); /* 6 sigma is excessive, but this check should be enough to
                                            * identify catastrophic failure while minimizing false