diff --git a/JsonGeneratorTests/StringBuilder.cpp b/JsonGeneratorTests/StringBuilder.cpp index ff67d5a9..c7230199 100644 --- a/JsonGeneratorTests/StringBuilder.cpp +++ b/JsonGeneratorTests/StringBuilder.cpp @@ -8,6 +8,11 @@ void StringBuilder::append(const char* s) { + if (!s) + { + return append("null"); + } + char* tail = buffer + length; while (*s && length capacity - 3) return; + if (length > capacity - 2) + { + // not enough from for quotes + return; + } buffer[length++] = '"'; diff --git a/JsonGeneratorTests/StringBuilderAppendTests.cpp b/JsonGeneratorTests/StringBuilderAppendTests.cpp index d5350a41..900895d0 100644 --- a/JsonGeneratorTests/StringBuilderAppendTests.cpp +++ b/JsonGeneratorTests/StringBuilderAppendTests.cpp @@ -28,6 +28,12 @@ namespace JsonGeneratorTests assertResultIs(""); } + TEST_METHOD(Null) + { + append(NULL); + assertResultIs("null"); + } + TEST_METHOD(OneString) { append("ABCD");