File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -518,7 +518,7 @@ Json::Value obj_value(Json::objectValue); // {}
518518 LargestUInt uint_;
519519 double real_;
520520 bool bool_;
521- char * string_;
521+ char * string_; // actually ptr to unsigned, followed by str
522522 ObjectValues* map_;
523523 } value_;
524524 ValueType type_ : 8 ;
Original file line number Diff line number Diff line change @@ -100,6 +100,28 @@ static inline char* duplicateStringValue(const char* value,
100100 return newString;
101101}
102102
103+ /* Record the length as a prefix.
104+ */
105+ static inline char * duplicatePrefixedStringValue (
106+ const char * value,
107+ unsigned int length = unknown)
108+ {
109+ if (length == unknown)
110+ length = (unsigned int )strlen (value);
111+
112+ // Avoid an integer overflow in the call to malloc below by limiting length
113+ // to a sane value.
114+ if (length >= (unsigned )Value::maxInt)
115+ length = Value::maxInt - 1 ;
116+
117+ char * newString = static_cast <char *>(malloc (length + 1 ));
118+ JSON_ASSERT_MESSAGE (newString != 0 ,
119+ " in Json::Value::duplicateStringValue(): "
120+ " Failed to allocate string value buffer" );
121+ memcpy (newString, value, length);
122+ newString[length] = 0 ;
123+ return newString;
124+ }
103125/* * Free the string duplicated by duplicateStringValue().
104126 */
105127static inline void releaseStringValue (char * value) { free (value); }
You can’t perform that action at this time.
0 commit comments