From: Zbigniew Jędrzejewski-Szmek Date: Sun, 7 Apr 2024 09:05:42 +0000 (+0200) Subject: core: silence gcc warning about unitialized variable X-Git-Tag: v256-rc1~285^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=741f6ae39be136f65fbc7fe424b7087f3ad23b0b;p=thirdparty%2Fsystemd.git core: silence gcc warning about unitialized variable When compiled with -O2, the compiler is not happy about dynamic_user_pop() and would warn about the output variables not being set. It does have a point: we were doing a cast from ssize_t to int, and theoretically there could be wraparound. So let's add an explicit check that the cast to int is fine. [540/2509] Compiling C object src/core/libsystemd-core-256.so.p/dynamic-user.c.o ../src/core/dynamic-user.c: In function ‘dynamic_user_close.isra’: ../src/core/dynamic-user.c:580:9: warning: ‘uid’ may be used uninitialized [-Wmaybe-uninitialized] 580 | unlink_uid_lock(lock_fd, uid, d->name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/core/dynamic-user.c:560:15: note: ‘uid’ was declared here 560 | uid_t uid; | ^~~ ../src/core/dynamic-user.c: In function ‘dynamic_user_realize’: ../src/core/dynamic-user.c:476:29: warning: ‘new_uid’ may be used uninitialized [-Wmaybe-uninitialized] 476 | num = new_uid; | ~~~~^~~~~~~~~ ../src/core/dynamic-user.c:398:23: note: ‘new_uid’ was declared here 398 | uid_t new_uid; | ^~~~~~~ --- diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index 24ed889b61e..11de2ba82b1 100644 --- a/src/core/dynamic-user.c +++ b/src/core/dynamic-user.c @@ -336,8 +336,10 @@ static int dynamic_user_pop(DynamicUser *d, uid_t *ret_uid, int *ret_lock_fd) { * the lock on the socket taken. */ k = receive_one_fd_iov(d->storage_socket[0], &iov, 1, MSG_DONTWAIT, &lock_fd); - if (k < 0) + if (k < 0) { + assert(errno_is_valid(-k)); return (int) k; + } *ret_uid = uid; *ret_lock_fd = lock_fd;