From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: avoid false-positive -Wmaybe-uninitialized through waitpid()
Date: Mon, 7 Jul 2025 15:17:24 +0200 [thread overview]
Message-ID: <20250707131724.GA32206@1wt.eu> (raw)
In-Reply-To: <20250707-nolibc-waitpid-uninitialized-v1-1-dcd4e70bcd8f@linutronix.de>
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@1wt.eu>
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
prev parent reply other threads:[~2025-07-07 13:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 12:58 Thomas Weißschuh
2025-07-07 13:17 ` Willy Tarreau [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250707131724.GA32206@1wt.eu \
--to=w@1wt.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=thomas.weissschuh@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®