From: Zbigniew Jędrzejewski-Szmek Date: Tue, 8 Jul 2025 10:55:17 +0000 (+0200) Subject: test-string-util: add a small test for xsprintf X-Git-Tag: v258-rc1~136^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e99c4e2be7bf27ca2bc14b528232aef0b1715aa;p=thirdparty%2Fsystemd.git test-string-util: add a small test for xsprintf --- diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 90ac5797075..4f12ec710c1 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -9,6 +9,19 @@ #include "strv.h" #include "tests.h" +TEST(xsprintf) { + char buf[5]; + + xsprintf(buf, "asdf"); + xsprintf(buf, "%4s", "a"); + xsprintf(buf, "%-4s", "a"); + xsprintf(buf, "%04d", 1); + + ASSERT_SIGNAL(xsprintf(buf, "asdfe"), SIGABRT); + ASSERT_SIGNAL(xsprintf(buf, "asdfefghdhdhdhdhd"), SIGABRT); + ASSERT_SIGNAL(xsprintf(buf, "%5s", "a"), SIGABRT); +} + TEST(string_erase) { char *x; x = strdupa_safe("");