Skip to content

Commit 7d8eddb

Browse files
authored
Merge pull request open-source-parsers#519 from open-source-parsers/fix-517
Avoid null for stringValue
2 parents b14c8c1 + 7e0571b commit 7d8eddb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/lib_json/json_value.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
343343
* This optimization is used in ValueInternalMap fast allocator.
344344
*/
345345
Value::Value(ValueType vtype) {
346+
static char const empty[] = "";
346347
initBasic(vtype);
347348
switch (vtype) {
348349
case nullValue:
@@ -355,7 +356,8 @@ Value::Value(ValueType vtype) {
355356
value_.real_ = 0.0;
356357
break;
357358
case stringValue:
358-
value_.string_ = 0;
359+
// allocated_ == false, so this is safe.
360+
value_.string_ = const_cast<char*>(static_cast<char const*>(empty));
359361
break;
360362
case arrayValue:
361363
case objectValue:

src/lib_json/json_writer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void FastWriter::writeValue(const Value& value) {
353353
break;
354354
case stringValue:
355355
{
356-
// Is NULL possible for value.string_?
356+
// Is NULL possible for value.string_? No.
357357
char const* str;
358358
char const* end;
359359
bool ok = value.getString(&str, &end);
@@ -423,7 +423,7 @@ void StyledWriter::writeValue(const Value& value) {
423423
break;
424424
case stringValue:
425425
{
426-
// Is NULL possible for value.string_?
426+
// Is NULL possible for value.string_? No.
427427
char const* str;
428428
char const* end;
429429
bool ok = value.getString(&str, &end);
@@ -640,7 +640,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
640640
break;
641641
case stringValue:
642642
{
643-
// Is NULL possible for value.string_?
643+
// Is NULL possible for value.string_? No.
644644
char const* str;
645645
char const* end;
646646
bool ok = value.getString(&str, &end);
@@ -921,7 +921,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
921921
break;
922922
case stringValue:
923923
{
924-
// Is NULL is possible for value.string_?
924+
// Is NULL is possible for value.string_? No.
925925
char const* str;
926926
char const* end;
927927
bool ok = value.getString(&str, &end);

0 commit comments

Comments
 (0)