Duplicates the specified string value. * @param value Pointer to the string to duplicate. Must be zero-terminated if * length is "unknown". * @param length Length of the value. if equals to unknown, then it will be * computed using strlen(value). * @return Pointer on the duplicate instance of string. */
| 2253 | * @return Pointer on the duplicate instance of string. |
| 2254 | */ |
| 2255 | static inline char* duplicateStringValue(const char* value, |
| 2256 | size_t length) { |
| 2257 | // Avoid an integer overflow in the call to malloc below by limiting length |
| 2258 | // to a sane value. |
| 2259 | if (length >= (size_t)Value::maxInt) |
| 2260 | length = Value::maxInt - 1; |
| 2261 | |
| 2262 | char* newString = static_cast<char*>(OG_MALLOC(length + 1)); |
| 2263 | if (newString == NULL) { |
| 2264 | throwRuntimeError( |
| 2265 | "in Json::Value::duplicateStringValue(): " |
| 2266 | "Failed to allocate string value buffer"); |
| 2267 | } |
| 2268 | memcpy(newString, value, length); |
| 2269 | newString[length] = 0; |
| 2270 | return newString; |
| 2271 | } |
| 2272 | |
| 2273 | /* Record the length as a prefix. |
| 2274 | */ |
no test coverage detected