From 741f6ae39be136f65fbc7fe424b7087f3ad23b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 7 Apr 2024 11:05:42 +0200 Subject: [PATCH] core: silence gcc warning about unitialized variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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; | ^~~~~~~ --- src/core/dynamic-user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c index 24ed889b61..11de2ba82b 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;