]> git.ipfire.org Git - thirdparty/shadow.git/commit
tests/unit/test_exit_if_null.c: Test through XMALLOC() instead of xaprintf() master
authorAlejandro Colomar <alx@kernel.org>
Tue, 4 Nov 2025 12:37:26 +0000 (13:37 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 6 Nov 2025 12:31:01 +0000 (13:31 +0100)
commit7d4362ff9d3eea118334ea4e1a99b03a359c516d
treedd71d85cdea6c1f97bf78137855e05eeb0d3722e
parent17ad06b379623b1fc6efd58c1ff0db4c37d99bd0
tests/unit/test_exit_if_null.c: Test through XMALLOC() instead of xaprintf()

Both are indirect tests for exit_if_null(), but through XMALLOC() we
can test it more robustly, as we don't need to wrap vasprintf(3) to
make it fail.  It's trivial to make MALLOC(3) fail: pass a huge size.

The tests with xaprintf() were failing on Nix.  I suspect the compiler
was inlining aggressively, and as a result, the interposition of
vasprintf(3) in cmocka wasn't actually working.  The approach with
XMALLOC() seems to work on Nix, as we don't need to interpose malloc(3).
We still need to interpose exit(3), but for some reason that works fine.

Closes: <https://github.com/shadow-maint/shadow/issues/1382>
Reported-by: Silvan Mosberger <github@infinisil.com>
Tested-by: Silvan Mosberger <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
tests/unit/Makefile.am
tests/unit/test_exit_if_null.c