summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-08-30 09:28:56 +0200
committerJan Janssen <medhefgo@web.de>2022-08-30 12:03:33 +0200
commit5570a09702b2a4c77772617d5fce97b6b70ec03f (patch)
tree6894fe53f7ed84cce0f20d1190648e0797ca8023
parenttree-wide: Fix a some remaining format warnings by casting (diff)
downloadsystemd-5570a09702b2a4c77772617d5fce97b6b70ec03f.tar.xz
systemd-5570a09702b2a4c77772617d5fce97b6b70ec03f.zip
tree-wide: Fix format specifier warnings for %x
Unfortunately, hex output can only be produced with unsigned types. Some cases can be fixed by producing the correct type, but a few simply have to be cast. At least casting makes it explicit.
-rw-r--r--src/cgtop/cgtop.c2
-rw-r--r--src/libsystemd-network/test-dhcp-option.c4
-rw-r--r--src/shared/json.c2
-rw-r--r--src/sysupdate/sysupdate-pattern.c5
-rw-r--r--src/test/test-coredump-util.c2
-rw-r--r--src/test/test-nss-hosts.c4
-rw-r--r--src/test/test-string-util.c4
-rw-r--r--src/timesync/wait-sync.c2
-rw-r--r--src/udev/cdrom_id/cdrom_id.c8
-rw-r--r--src/udev/scsi_id/scsi_id.c2
-rw-r--r--src/udev/scsi_id/scsi_serial.c9
11 files changed, 22 insertions, 22 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index b023e71757..46f4624048 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -1086,7 +1086,7 @@ static int run(int argc, char *argv[]) {
default:
if (key < ' ')
- fprintf(stdout, "\nUnknown key '\\x%x'. Ignoring.", key);
+ fprintf(stdout, "\nUnknown key '\\x%x'. Ignoring.", (unsigned) key);
else
fprintf(stdout, "\nUnknown key '%c'. Ignoring.", key);
fflush(stdout);
diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c
index ec4f9706d5..82c5cdb67a 100644
--- a/src/libsystemd-network/test-dhcp-option.c
+++ b/src/libsystemd-network/test-dhcp-option.c
@@ -339,13 +339,13 @@ static void test_option_set(void) {
if (verbose)
printf("%2d: 0x%02x(0x%02x) (options)\n", 9, result->options[9],
- SD_DHCP_OPTION_END);
+ (unsigned) SD_DHCP_OPTION_END);
assert_se(result->options[9] == SD_DHCP_OPTION_END);
if (verbose)
printf("%2d: 0x%02x(0x%02x) (options)\n", 10, result->options[10],
- SD_DHCP_OPTION_PAD);
+ (unsigned) SD_DHCP_OPTION_PAD);
assert_se(result->options[10] == SD_DHCP_OPTION_PAD);
diff --git a/src/shared/json.c b/src/shared/json.c
index 919f7f79db..f0416e66dc 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -1512,7 +1512,7 @@ static void json_format_string(FILE *f, const char *q, JsonFormatFlags flags) {
default:
if ((signed char) *q >= 0 && *q < ' ')
- fprintf(f, "\\u%04x", *q);
+ fprintf(f, "\\u%04x", (unsigned) *q);
else
fputc(*q, f);
break;
diff --git a/src/sysupdate/sysupdate-pattern.c b/src/sysupdate/sysupdate-pattern.c
index c9228687f7..6d9c8d8f8b 100644
--- a/src/sysupdate/sysupdate-pattern.c
+++ b/src/sysupdate/sysupdate-pattern.c
@@ -148,7 +148,10 @@ static int pattern_split(
}
if (!valid_char(*e))
- return log_debug_errno(SYNTHETIC_ERRNO(EBADRQC), "Invalid character 0x%0x in pattern, refusing.", *e);
+ return log_debug_errno(
+ SYNTHETIC_ERRNO(EBADRQC),
+ "Invalid character 0x%0x in pattern, refusing.",
+ (unsigned) *e);
last_literal = true;
diff --git a/src/test/test-coredump-util.c b/src/test/test-coredump-util.c
index a669da7746..40b68df9f4 100644
--- a/src/test/test-coredump-util.c
+++ b/src/test/test-coredump-util.c
@@ -10,7 +10,7 @@ TEST(coredump_filter_to_from_string) {
const char *n;
assert_se(n = coredump_filter_to_string(i));
- log_info("0x%x\t%s", 1<<i, n);
+ log_info("0x%x\t%s", 1u << i, n);
assert_se(coredump_filter_from_string(n) == i);
uint64_t f;
diff --git a/src/test/test-nss-hosts.c b/src/test/test-nss-hosts.c
index c361df1632..defecd3a51 100644
--- a/src/test/test-nss-hosts.c
+++ b/src/test/test-nss-hosts.c
@@ -114,10 +114,10 @@ static void test_gethostbyname4_r(void *handle, const char *module, const char *
status = f(name, &pat, buffer, sizeof buffer, &errno1, &errno2, &ttl);
if (status == NSS_STATUS_SUCCESS) {
- log_info("%s(\"%s\") → status=%s%-20spat=buffer+0x%tx errno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
+ log_info("%s(\"%s\") → status=%s%-20spat=buffer+0x%"PRIxPTR" errno=%d/%s h_errno=%d/%s ttl=%"PRIi32,
fname, name,
nss_status_to_string(status, pretty_status, sizeof pretty_status), "\n",
- pat ? (char*) pat - buffer : 0,
+ pat ? (uintptr_t) pat - (uintptr_t) buffer : 0,
errno1, errno_to_name(errno1) ?: "---",
errno2, hstrerror(errno2),
ttl);
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c
index f5d7ab12b5..25ddceb799 100644
--- a/src/test/test-string-util.c
+++ b/src/test/test-string-util.c
@@ -1106,7 +1106,7 @@ TEST(strextendf) {
assert_se(strextendf(&p, "<%80i>", 88) >= 0);
assert_se(streq(p, "<77><99>< 88>"));
- assert_se(strextendf(&p, "<%08x>", 0x1234) >= 0);
+ assert_se(strextendf(&p, "<%08x>", 0x1234u) >= 0);
assert_se(streq(p, "<77><99>< 88><00001234>"));
p = mfree(p);
@@ -1120,7 +1120,7 @@ TEST(strextendf) {
assert_se(strextendf_with_separator(&p, ",", "<%80i>", 88) >= 0);
assert_se(streq(p, "<77>,<99>,< 88>"));
- assert_se(strextendf_with_separator(&p, ",", "<%08x>", 0x1234) >= 0);
+ assert_se(strextendf_with_separator(&p, ",", "<%08x>", 0x1234u) >= 0);
assert_se(streq(p, "<77>,<99>,< 88>,<00001234>"));
}
diff --git a/src/timesync/wait-sync.c b/src/timesync/wait-sync.c
index 57e6cd3403..44de4932fd 100644
--- a/src/timesync/wait-sync.c
+++ b/src/timesync/wait-sync.c
@@ -147,7 +147,7 @@ static int clock_state_update(
tx.time.tv_usec /= 1000;
t = timeval_load(&tx.time);
- log_info("adjtime state %d status %x time %s", sp->adjtime_state, tx.status,
+ log_info("adjtime state %i status %x time %s", sp->adjtime_state, (unsigned) tx.status,
FORMAT_TIMESTAMP_STYLE(t, TIMESTAMP_US_UTC) ?: "unrepresentable");
sp->has_watchfile = access("/run/systemd/timesync/synchronized", F_OK) >= 0;
diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index d2c1262121..2d758c4082 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -140,9 +140,9 @@ static int set_drive_feature(Context *c, Feature f) {
}
#define ERRCODE(s) ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
-#define SK(errcode) (((errcode) >> 16) & 0xF)
-#define ASC(errcode) (((errcode) >> 8) & 0xFF)
-#define ASCQ(errcode) ((errcode) & 0xFF)
+#define SK(errcode) (((errcode) >> 16) & 0xFU)
+#define ASC(errcode) (((errcode) >> 8) & 0xFFU)
+#define ASCQ(errcode) ((errcode) & 0xFFU)
#define CHECK_CONDITION 0x01
static int log_scsi_debug_errno(int error, const char *msg) {
@@ -712,7 +712,7 @@ static int cd_media_toc(Context *c) {
block = unaligned_read_be32(&toc[i + 4]);
log_debug("track=%u info=0x%x(%s) start_block=%"PRIu32,
- toc[i + 2], toc[i + 1] & 0x0f, is_data_track ? "data":"audio", block);
+ toc[i + 2], toc[i + 1] & 0x0FU, is_data_track ? "data":"audio", block);
if (is_data_track)
c->media_track_count_data++;
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index 8ce73d03da..364d567705 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -357,7 +357,7 @@ static int per_dev_options(struct scsi_id_device *dev_scsi, int *good_bad, int *
break;
default:
- log_error("Unknown or bad option '%c' (0x%x)", option, option);
+ log_error("Unknown or bad option '%c' (0x%x)", option, (unsigned) option);
retval = -1;
break;
}
diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c
index 299ccb96fb..47c2a5cb4f 100644
--- a/src/udev/scsi_id/scsi_serial.c
+++ b/src/udev/scsi_id/scsi_serial.c
@@ -154,10 +154,7 @@ static int sg_err_category4(struct sg_io_v4 *hp) {
static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
unsigned char *sense_buffer, int sb_len) {
int s;
- int code;
- int sense_class;
- int sense_key;
- int asc, ascq;
+ unsigned code, sense_class, sense_key, asc, ascq;
/*
* Figure out and print the sense key, asc and ascq.
@@ -221,11 +218,11 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
4 - sb_len);
if (sense_buffer[0] < 15)
- log_debug("%s: old sense key: 0x%x", dev_scsi->kernel, sense_buffer[0] & 0x0f);
+ log_debug("%s: old sense key: 0x%x", dev_scsi->kernel, sense_buffer[0] & 0x0fu);
else
log_debug("%s: sense = %2x %2x",
dev_scsi->kernel, sense_buffer[0], sense_buffer[2]);
- log_debug("%s: non-extended sense class %d code 0x%0x",
+ log_debug("%s: non-extended sense class %u code 0x%0x",
dev_scsi->kernel, sense_class, code);
}