Avoid null for stringValue

fixes #517
This commit is contained in:
Christopher Dunn 2016-08-21 16:25:29 -05:00
parent b14c8c1423
commit 7e0571b444
2 changed files with 7 additions and 5 deletions

View File

@ -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<char*>(static_cast<char const*>(empty));
break;
case arrayValue:
case objectValue:

View File

@ -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);