@@ -87,9 +87,11 @@ static inline char* duplicateStringValue(const char* value,
8787 length = Value::maxInt - 1 ;
8888
8989 char * newString = static_cast <char *>(malloc (length + 1 ));
90- JSON_ASSERT_MESSAGE (newString != 0 ,
91- " in Json::Value::duplicateStringValue(): "
92- " Failed to allocate string value buffer" );
90+ if (newString == NULL ) {
91+ throw std::runtime_error (
92+ " in Json::Value::duplicateStringValue(): "
93+ " Failed to allocate string value buffer" );
94+ }
9395 memcpy (newString, value, length);
9496 newString[length] = 0 ;
9597 return newString;
@@ -108,9 +110,11 @@ static inline char* duplicateAndPrefixStringValue(
108110 " length too big for prefixing" );
109111 unsigned actualLength = length + sizeof (unsigned ) + 1U ;
110112 char * newString = static_cast <char *>(malloc (actualLength));
111- JSON_ASSERT_MESSAGE (newString != 0 ,
112- " in Json::Value::duplicateAndPrefixStringValue(): "
113- " Failed to allocate string value buffer" );
113+ if (newString == 0 ) {
114+ throw std::runtime_error (
115+ " in Json::Value::duplicateAndPrefixStringValue(): "
116+ " Failed to allocate string value buffer" );
117+ }
114118 *reinterpret_cast <unsigned *>(newString) = length;
115119 memcpy (newString + sizeof (unsigned ), value, length);
116120 newString[actualLength - 1U ] = 0 ; // to avoid buffer over-run accidents by users later
0 commit comments