From 4c60962cd0245b71be23366c5a1425934403226c Mon Sep 17 00:00:00 2001 From: Raj Date: Thu, 8 Oct 2026 12:30:40 +0530 Subject: [PATCH] test(libc): put sprintf, sscanf and libc_printf arguments on the stack guest_formatting called sprintf with four variadic arguments and libc_printf with one, all in registers, and did not call sscanf, so only snprintf had a check that fails with the old Linux register rebuild. sprintf now formats six integers, sscanf converts eight fields and libc_printf prints seven integers; on the old code the first gives "1 2 3 4 0 0" and the other two crash. Checks suggested by nauroth in #1435. --- core/libs/tests/Formatting.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/libs/tests/Formatting.cpp b/core/libs/tests/Formatting.cpp index 0448df21f..6cccc4a31 100644 --- a/core/libs/tests/Formatting.cpp +++ b/core/libs/tests/Formatting.cpp @@ -8,6 +8,7 @@ int APS5_VABI snprintf_nid_postfix(char*, size_t, const char*, ...); int APS5_VABI sprintf_nid_postfix(char*, const char*, ...); int APS5_VABI printf_nid_postfix(const char*, ...); int APS5_VABI libc_printf_nid_postfix(const char*, ...); +int APS5_VABI sscanf_nid_postfix(const char*, const char*, ...); int APS5_VABI vsnprintf_nid_postfix(char*, size_t, const char*, VaList*); int APS5_VABI vprintf_nid_postfix(const char*, VaList*); } @@ -103,6 +104,15 @@ __attribute__((noinline)) static void APS5_VABI RunChecks() { Require(snprintf_nid_postfix(buffer, 1, "%d", 123) == 3 && buffer[0] == 0); Require(sprintf_nid_postfix(buffer, "%hhd %hhu %hd %hu %%", 255, 257, 65535, 65537) == 11); Require(std::strcmp(buffer, "-1 1 -1 1 %") == 0); + Require(sprintf_nid_postfix(buffer, "%d %d %d %d %d %d", 1, 2, 3, 4, 5, 6) == 11); + Require(std::strcmp(buffer, "1 2 3 4 5 6") == 0); + int first = 0, second = 0, third = 0, fourth = 0, fifth = 0, sixth = 0; + char word[16] = {}; + double real = 0.0; + Require(sscanf_nid_postfix("1 2 3 4 5 6 seven 8.5", "%d %d %d %d %d %d %15s %lf", + &first, &second, &third, &fourth, &fifth, &sixth, word, &real) == 8); + Require(first == 1 && second == 2 && third == 3 && fourth == 4 && fifth == 5 && sixth == 6); + Require(std::strcmp(word, "seven") == 0 && real == 8.5); long long count = -1; int smallCount = -1; Require(snprintf_nid_postfix(buffer, 3, "abcd%lnEF%n", &count, &smallCount) == 6); @@ -111,6 +121,7 @@ __attribute__((noinline)) static void APS5_VABI RunChecks() { Require(buffer[0] == 'a' && buffer[1] == 0 && buffer[2] == 'b' && buffer[3] == 0); Require(printf_nid_postfix("printf: %d %.1f\n", 7, 2.5) == 14); Require(libc_printf_nid_postfix("libc_printf: %s\n", "OK") == 16); + Require(libc_printf_nid_postfix("%d %d %d %d %d %d %d\n", 1, 22, 333, 4444, 55555, 666666, 7777777) == 35); Require(PrintList("vprintf: %d\n", 42) == 12); std::puts("Formatting checks passed: 10000 iterations"); }