From a5f5c3fd33ebc91e827e0b0ab94d438cc82ffff4 Mon Sep 17 00:00:00 2001 From: asynts Date: Sun, 25 Oct 2020 18:17:14 +0100 Subject: [PATCH] LibC+Tests: Fix broken snprintf test. `snprintf` returns the number of characters that would have been written had the buffer been large enough. It's a common trick to call `snprintf(nullptr, 0, ...)` to measure how large a buffer has to be. Thus the return value is not zero but fourteen. --- Userland/Tests/LibC/snprintf-correctness.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Tests/LibC/snprintf-correctness.cpp b/Userland/Tests/LibC/snprintf-correctness.cpp index abd409a634..dee19fe2c7 100644 --- a/Userland/Tests/LibC/snprintf-correctness.cpp +++ b/Userland/Tests/LibC/snprintf-correctness.cpp @@ -155,7 +155,7 @@ TEST_CASE(too_long) TEST_CASE(special_cases) { EXPECT(test_single({ LITERAL(""), "Hello Friend!", POISON, 13, LITERAL("") })); - EXPECT_EQ(snprintf(nullptr, 0, "Hello, friend!"), 0); + EXPECT_EQ(snprintf(nullptr, 0, "Hello, friend!"), 14); EXPECT(test_single({ LITERAL(""), "", POISON, 0, LITERAL("") })); EXPECT(test_single({ LITERAL("x"), "", POISON, 0, LITERAL("\0") })); EXPECT(test_single({ LITERAL("xx"), "", POISON, 0, LITERAL("\0x") }));