On Fri, 17 Feb 2023 09:29:51 -0500
Laine Stump
On 2/16/23 5:53 PM, David Gibson wrote:
On Thu, Feb 16, 2023 at 07:22:10PM +0100, Stefano Brivio wrote:
The newly introduced die() calls exit(), but cppcheck doesn't see it and warns about possibly invalid arguments used after the check which triggers die(). Add return statements to silence the warnings.
Signed-off-by: Stefano Brivio
Oof, that's super ugly. Any chance that cppcheck will recognize the ((noreturn)) attribute if we added it to die()?
Why is this only a problem in these two files?
Because that's where we would use a variable as a system call argument, if the check possibly leading to die() didn't exist.
(and is there a "make check" target that I should have been running and haven't?)
make cppcheck, make clang-tidy, and possibly the tests (see test/README.md) -- but it's not mandatory, especially if you're an occasional contributor, I'm running them anyway.
Requiring an extra "return" after die() kind of removes the advantage of using it over err(). :-/ If we have to do that, it would be more straightforward to just use err() followed by exit() directly.
We don't have to (see the rest of this thread): we could simply define die() as err() with an additional return statement *outside* err() itself, instead of passing 'doexit' as parameter. Probably something like: do { err(...) exit(EXIT_FAILURE); return; } while (0) -- Stefano