From: Zbigniew Jędrzejewski-Szmek Date: Sun, 7 Apr 2024 09:13:06 +0000 (+0200) Subject: sd-bus: rework assert to make the gcc happy X-Git-Tag: v256-rc1~285^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F32135%2Fhead;p=thirdparty%2Fsystemd.git sd-bus: rework assert to make the gcc happy With gcc-14.0.1-0.13.fc40, when compiling with -O2, the compiler doesn't understand that sd_bus_error_setf() always returns negative on error when is provided: [28/576] Compiling C object systemd-resolved.p/src_resolve_resolved-bus.c.o ../src/resolve/resolved-bus.c: In function ‘call_link_method’: ../src/resolve/resolved-bus.c:1763:16: warning: ‘l’ may be used uninitialized [-Wmaybe-uninitialized] 1763 | return handler(message, l, error); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/resolve/resolved-bus.c:1749:15: note: ‘l’ was declared here 1749 | Link *l; | ^ ../src/resolve/resolved-bus.c: In function ‘bus_method_get_link’: ../src/resolve/resolved-bus.c:1822:13: warning: ‘l’ may be used uninitialized [-Wmaybe-uninitialized] 1822 | p = link_bus_path(l); | ^~~~~~~~~~~~~~~~ ../src/resolve/resolved-bus.c:1810:15: note: ‘l’ was declared here 1810 | Link *l; | ^ ... Let's make the assertion a bit more explicit. With this, the warning goes away, but I think it's more obvious to a human reader too. --- diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index 77b2e1a0fde..f415797700e 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -277,14 +277,16 @@ _public_ int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *fo va_start(ap, format); r = sd_bus_error_setfv(e, name, format, ap); - assert(!name || r < 0); + if (name) + assert(r < 0); va_end(ap); return r; } r = sd_bus_error_set(e, name, NULL); - assert(!name || r < 0); + if (name) + assert(r < 0); return r; }