diff options
author | Jan Janssen <medhefgo@web.de> | 2022-08-30 09:52:03 +0200 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2022-08-30 12:03:33 +0200 |
commit | f996072fe05358ac24460dff1dc12dd804bf210d (patch) | |
tree | 4f459f4caaec458b8b2007c4f487571977a8cb07 | |
parent | 5570a09702b2a4c77772617d5fce97b6b70ec03f (diff) | |
download | systemd-f996072fe05358ac24460dff1dc12dd804bf210d.tar.gz |
tree-wide: Fix field width specifier warnings
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.
-rw-r--r-- | src/cgtop/cgtop.c | 6 | ||||
-rw-r--r-- | src/firstboot/firstboot.c | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-match.c | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-journal/test-journal-send.c | 4 | ||||
-rw-r--r-- | src/resolve/resolvectl.c | 2 | ||||
-rw-r--r-- | src/shared/cgroup-show.c | 2 | ||||
-rw-r--r-- | src/shared/logs-show.c | 13 | ||||
-rw-r--r-- | src/test/test-random-util.c | 2 |
8 files changed, 17 insertions, 16 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 46f4624048..95c3987525 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -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)); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index fd9954b54d..abeafacc38 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -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'); diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index d4da60717e..157c660fe9 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -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) diff --git a/src/libsystemd/sd-journal/test-journal-send.c b/src/libsystemd/sd-journal/test-journal-send.c index 8f9d9c4a30..ca1fe7c303 100644 --- a/src/libsystemd/sd-journal/test-journal-send.c +++ b/src/libsystemd/sd-journal/test-journal-send.c @@ -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) { diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 8e6620d604..677e77b081 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -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); } } diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index f3f97f6cac..ca96e198f3 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -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()); } } diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 5e2fd580db..98219e14fa 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -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 diff --git a/src/test/test-random-util.c b/src/test/test-random-util.c index 3128f669b7..e5972718b4 100644 --- a/src/test/test-random-util.c +++ b/src/test/test-random-util.c @@ -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 |