summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Laight <david.laight.linux@gmail.com>2026-03-02 13:17:56 +0300
committerThomas Weißschuh <linux@weissschuh.net>2026-03-20 19:46:02 +0300
commit9aa8a4afd4e6407a4d4521c325855c4467a88b73 (patch)
treecc1665cf37f15c17eac0fb5588ac122d0540d738
parentb42f02da2bf99460a7b1c5c25008f2e4a65ea4e3 (diff)
downloadlinux-9aa8a4afd4e6407a4d4521c325855c4467a88b73.tar.xz
selftests/nolibc: check vsnprintf() output buffer before the length
Check the string matches before checking the returned length. Only print the string once when it matches. Makes it a lot easier to diagnose any incorrect output. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260302101815.3043-5-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 7588212df124..bfe793caa963 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1676,25 +1676,27 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
char buf[100];
va_list args;
ssize_t w;
- int ret;
-
va_start(args, fmt);
/* Only allow writing 21 bytes, to test truncation */
w = vsnprintf(buf, 21, fmt, args);
va_end(args);
+ llen += printf(" \"%s\"", buf);
+ if (strncmp(expected, buf, c)) {
+ llen += printf(" should be \"%s\"", expected);
+ result(llen, FAIL);
+ return 1;
+ }
+
if (w != c) {
llen += printf(" written(%d) != %d", (int)w, c);
result(llen, FAIL);
return 1;
}
- llen += printf(" \"%s\" = \"%s\"", expected, buf);
- ret = strncmp(expected, buf, c) != 0;
-
- result(llen, ret ? FAIL : OK);
- return ret;
+ result(llen, OK);
+ return 0;
}
static int test_scanf(void)