mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
vsnprintf: Fix crash when _out is NULL.
This commit is contained in:
@@ -1230,7 +1230,8 @@ namespace bx
|
||||
|
||||
int32_t vsnprintf(char* _out, int32_t _max, const char* _format, va_list _argList)
|
||||
{
|
||||
if (0 < _max)
|
||||
if ( 0 < _max
|
||||
&& NULL != _out)
|
||||
{
|
||||
StaticMemoryBlockWriter writer(_out, uint32_t(_max) );
|
||||
|
||||
|
||||
@@ -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!") );
|
||||
|
||||
Reference in New Issue
Block a user