提交 7d8eddb9 编写于 作者: C Christopher Dunn 提交者: GitHub

Merge pull request #519 from open-source-parsers/fix-517

Avoid null for stringValue
...@@ -343,6 +343,7 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl ...@@ -343,6 +343,7 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl
* This optimization is used in ValueInternalMap fast allocator. * This optimization is used in ValueInternalMap fast allocator.
*/ */
Value::Value(ValueType vtype) { Value::Value(ValueType vtype) {
static char const empty[] = "";
initBasic(vtype); initBasic(vtype);
switch (vtype) { switch (vtype) {
case nullValue: case nullValue:
...@@ -355,7 +356,8 @@ Value::Value(ValueType vtype) { ...@@ -355,7 +356,8 @@ Value::Value(ValueType vtype) {
value_.real_ = 0.0; value_.real_ = 0.0;
break; break;
case stringValue: case stringValue:
value_.string_ = 0; // allocated_ == false, so this is safe.
value_.string_ = const_cast<char*>(static_cast<char const*>(empty));
break; break;
case arrayValue: case arrayValue:
case objectValue: case objectValue:
......
...@@ -353,7 +353,7 @@ void FastWriter::writeValue(const Value& value) { ...@@ -353,7 +353,7 @@ void FastWriter::writeValue(const Value& value) {
break; break;
case stringValue: case stringValue:
{ {
// Is NULL possible for value.string_? // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
...@@ -423,7 +423,7 @@ void StyledWriter::writeValue(const Value& value) { ...@@ -423,7 +423,7 @@ void StyledWriter::writeValue(const Value& value) {
break; break;
case stringValue: case stringValue:
{ {
// Is NULL possible for value.string_? // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
...@@ -640,7 +640,7 @@ void StyledStreamWriter::writeValue(const Value& value) { ...@@ -640,7 +640,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
break; break;
case stringValue: case stringValue:
{ {
// Is NULL possible for value.string_? // Is NULL possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
...@@ -921,7 +921,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { ...@@ -921,7 +921,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
break; break;
case stringValue: case stringValue:
{ {
// Is NULL is possible for value.string_? // Is NULL is possible for value.string_? No.
char const* str; char const* str;
char const* end; char const* end;
bool ok = value.getString(&str, &end); bool ok = value.getString(&str, &end);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册