Re: [PATCH] tools/nolibc: avoid false-positive -Wmaybe-uninitialized through waitpid()

From: Willy Tarreau
Date: Mon Jul 07 2025 - 09:18:07 EST


Hi Thomas,

On Mon, Jul 07, 2025 at 02:58:11PM +0200, Thomas Weißschuh wrote:
> 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.
(...)

Yeah that sounds reasonable for such use cases.

Acked-by: Willy Tarreau <w@xxxxxx>

FWIW when facing such cases sometimes it's also convenient to use
__builtin_unreachable() to let the compiler know the situation does
not exist. E.g:

ret = waitpid(...);
if (ret == -1)
...
if (ret != 0)
__builtin_unreachable();

But here it's overkill, plus not all compilers used in user land have
it so it quickly becomes a pain to define it depending on the compiler,
and your approach is much better for this case!

Willy