1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

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.
This commit is contained in:
asynts 2020-10-25 18:17:14 +01:00 committed by Andreas Kling
parent 0ab3488b60
commit a5f5c3fd33

View file

@ -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") }));