vsnprintf: Fix crash when _out is NULL.

This commit is contained in:
Бранимир Караџић
2024-12-04 19:23:10 -08:00
parent 4a1f0ab630
commit 32e578b22f
2 changed files with 10 additions and 1 deletions

View File

@@ -30,6 +30,14 @@ TEST_CASE("Truncated output buffer.", "[string][printf]")
REQUIRE(4 == bx::snprintf(buffer1, BX_COUNTOF(buffer1), "abvg") );
REQUIRE('\0' == buffer1[BX_COUNTOF(buffer1)-1]);
buffer1[0] = '\xfb'; // null destination
REQUIRE(4 == bx::snprintf(NULL, BX_COUNTOF(buffer1), "abvg") );
REQUIRE('\xfb' == buffer1[0]);
buffer1[0] = '\xbf'; // one byte destination
REQUIRE(4 == bx::snprintf(buffer1, 1, "abvg") );
REQUIRE('\0' == buffer1[0]);
char buffer7[7]; // truncate
REQUIRE(10 == bx::snprintf(NULL, 0, "Ten chars!") );
REQUIRE(10 == bx::snprintf(buffer7, BX_COUNTOF(buffer7), "Ten chars!") );