linux/tools/include/nolibc/sys
Thomas Weißschuh 31db7b6a78 tools/nolibc: avoid false-positive -Wmaybe-uninitialized through waitpid()
The compiler does not know that waitid() will only ever return 0 or -1.
If waitid() would return a positive value than waitpid() would return that
same value and *status would not be initialized.
However users calling waitpid() know that the only possible return values
of it are 0 or -1. They therefore might check for errors with
'ret == -1' or 'ret < 0' and use *status otherwise. The compiler will then
warn about the usage of a potentially uninitialized variable.

Example:

	$ cat test.c
	#include <stdio.h>
	#include <unistd.h>

	int main(void)
	{
		int ret, status;

		ret = waitpid(0, &status, 0);
		if (ret == -1)
			return 0;

		printf("status %x\n", status);

		return 0;
	}

	$ gcc --version
	gcc (GCC) 15.1.1 20250425

	$ gcc -Wall -Os -Werror -nostdlib -nostdinc -static -Iusr/include -Itools/include/nolibc/ -o /dev/null test.c
	test.c: In function ‘main’:
	test.c:12:9: error: ‘status’ may be used uninitialized [-Werror=maybe-uninitialized]
	   12 |         printf("status %x\n", status);
	      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	test.c:6:18: note: ‘status’ was declared here
	    6 |         int ret, status;
	      |                  ^~~~~~
	cc1: all warnings being treated as errors

Avoid the warning by normalizing waitid() errors to '-1' in waitpid().

Fixes: 0c89abf5ab ("tools/nolibc: implement waitpid() in terms of waitid()")
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250707-nolibc-waitpid-uninitialized-v1-1-dcd4e70bcd8f@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2025-07-07 15:24:35 +02:00
..
auxv.h tools/nolibc: include nolibc.h early from all header files 2025-05-21 15:31:50 +02:00
ioctl.h tools/nolibc: move ioctl() to sys/ioctl.h 2025-05-21 15:32:16 +02:00
mman.h tools/nolibc: add mremap() 2025-05-21 15:32:03 +02:00
mount.h tools/nolibc: move mount() to sys/mount.h 2025-05-21 15:32:18 +02:00
prctl.h tools/nolibc: move prctl() to sys/prctl.h 2025-05-21 15:32:19 +02:00
random.h tools/nolibc: add getrandom() 2025-05-21 15:32:04 +02:00
reboot.h tools/nolibc: move reboot() to sys/reboot.h 2025-05-21 15:32:20 +02:00
resource.h tools/nolibc: move getrlimit() and friends to sys/resource.h 2025-05-21 15:32:21 +02:00
stat.h tools/nolibc: add more stat() variants 2025-05-21 15:32:02 +02:00
syscall.h tools/nolibc: include nolibc.h early from all header files 2025-05-21 15:31:50 +02:00
sysmacros.h tools/nolibc: move makedev() and friends to sys/sysmacros.h 2025-05-21 15:32:23 +02:00
time.h tools/nolibc: fall back to sys_clock_gettime() in gettimeofday() 2025-05-21 15:32:15 +02:00
timerfd.h tools/nolibc: add timerfd functionality 2025-05-21 15:32:10 +02:00
types.h tools/nolibc: add sys/types.h shim 2025-04-19 14:22:29 +02:00
utsname.h tools/nolibc: move uname() and friends to sys/utsname.h 2025-05-21 15:32:24 +02:00
wait.h tools/nolibc: avoid false-positive -Wmaybe-uninitialized through waitpid() 2025-07-07 15:24:35 +02:00