From 7e0571b444497ad9a0a8547d76a06ef426c7116e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 21 Aug 2016 16:25:29 -0500 Subject: [PATCH] Avoid null for stringValue fixes #517 --- src/lib_json/json_value.cpp | 4 +++- src/lib_json/json_writer.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2fe4630..5adfef4 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -343,6 +343,7 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl * This optimization is used in ValueInternalMap fast allocator. */ Value::Value(ValueType vtype) { + static char const empty[] = ""; initBasic(vtype); switch (vtype) { case nullValue: @@ -355,7 +356,8 @@ Value::Value(ValueType vtype) { value_.real_ = 0.0; break; case stringValue: - value_.string_ = 0; + // allocated_ == false, so this is safe. + value_.string_ = const_cast(static_cast(empty)); break; case arrayValue: case objectValue: diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 35f0b1f..a0edff4 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -353,7 +353,7 @@ void FastWriter::writeValue(const Value& value) { break; case stringValue: { - // Is NULL possible for value.string_? + // Is NULL possible for value.string_? No. char const* str; char const* end; bool ok = value.getString(&str, &end); @@ -423,7 +423,7 @@ void StyledWriter::writeValue(const Value& value) { break; case stringValue: { - // Is NULL possible for value.string_? + // Is NULL possible for value.string_? No. char const* str; char const* end; bool ok = value.getString(&str, &end); @@ -640,7 +640,7 @@ void StyledStreamWriter::writeValue(const Value& value) { break; case stringValue: { - // Is NULL possible for value.string_? + // Is NULL possible for value.string_? No. char const* str; char const* end; bool ok = value.getString(&str, &end); @@ -921,7 +921,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { break; case stringValue: { - // Is NULL is possible for value.string_? + // Is NULL is possible for value.string_? No. char const* str; char const* end; bool ok = value.getString(&str, &end);