Skip to content

Commit 3e7d14d

Browse files
keszybzmartinpitt
authored andcommitted
sd-bus: silence format warnings in kdbus code (systemd#6072)
The code is mostly correct, but gcc is trying to outsmart us, and emits a warning for a "llu vs lu" mismatch, even though they are the same size (on alpha): src/libsystemd/sd-bus/bus-control.c: In function ‘kernel_get_list’: src/libsystemd/sd-bus/bus-control.c:267:42: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64 {aka long unsigned int}’ [-Werror=format=] if (asprintf(&n, ":1.%llu", name->id) < 0) { ^ src/libsystemd/sd-bus/bus-control.c: In function ‘bus_get_name_creds_kdbus’: src/libsystemd/sd-bus/bus-control.c:714:47: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64 {aka long unsigned int}’ [-Werror=format=] if (asprintf(&c->unique_name, ":1.%llu", conn_info->id) < 0) { ^ This is hard to work around properly, because kdbus.h uses __u64 which is defined-differently-despite-being-the-same-size then uint64_t. Thus the simple solution of using %PRIu64 fails on amd64: src/libsystemd/sd-bus/bus-control.c:714:47: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__u64 {aka long long unsigned int}’ [-Werror=format=] if (asprintf(&c->unique_name, ":1.%"PRIu64, conn_info->id) < 0) { ^~~~~~ Let's just avoid the whole issue for now by silencing the warning. After the next release, we should just get rid of the kdbus code. Fixes systemd#5561.
1 parent af4af18 commit 3e7d14d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/libsystemd/sd-bus/bus-control.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,13 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
264264
if ((flags & KDBUS_LIST_UNIQUE) && name->id != previous_id && !(name->flags & KDBUS_HELLO_ACTIVATOR)) {
265265
char *n;
266266

267+
#pragma GCC diagnostic push
268+
#pragma GCC diagnostic ignored "-Wformat"
267269
if (asprintf(&n, ":1.%llu", name->id) < 0) {
268270
r = -ENOMEM;
269271
goto fail;
270272
}
273+
#pragma GCC diagnostic pop
271274

272275
r = strv_consume(x, n);
273276
if (r < 0)
@@ -711,10 +714,13 @@ int bus_get_name_creds_kdbus(
711714
}
712715

713716
if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
717+
#pragma GCC diagnostic push
718+
#pragma GCC diagnostic ignored "-Wformat"
714719
if (asprintf(&c->unique_name, ":1.%llu", conn_info->id) < 0) {
715720
r = -ENOMEM;
716721
goto fail;
717722
}
723+
#pragma GCC diagnostic pop
718724

719725
c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
720726
}

src/libsystemd/sd-bus/bus-kernel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include "user-util.h"
5252
#include "util.h"
5353

54+
#pragma GCC diagnostic ignored "-Wformat"
55+
5456
#define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
5557

5658
int bus_kernel_parse_unique_name(const char *s, uint64_t *id) {

0 commit comments

Comments
 (0)