1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

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.
This commit is contained in:
Jan Janssen 2022-08-30 09:52:03 +02:00
parent 5570a09702
commit f996072fe0
8 changed files with 17 additions and 16 deletions

View 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));

View 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');

View 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)

View 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) {

View 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);
}
}

View 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());
}
}

View 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

View 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