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. */
| 2563 | * @return Pointer on the duplicate instance of string. |
| 2564 | */ |
| 2565 | static inline char* duplicateStringValue(const char* value, size_t length) { |
| 2566 | // Avoid an integer overflow in the call to malloc below by limiting length |
| 2567 | // to a sane value. |
| 2568 | if (length >= static_cast<size_t>(Value::maxInt)) |
| 2569 | length = Value::maxInt - 1; |
| 2570 | |
| 2571 | char* newString = static_cast<char*>(malloc(length + 1)); |
| 2572 | if (newString == NULL) { |
| 2573 | throwRuntimeError("in Json::Value::duplicateStringValue(): " |
| 2574 | "Failed to allocate string value buffer"); |
| 2575 | } |
| 2576 | memcpy(newString, value, length); |
| 2577 | newString[length] = 0; |
| 2578 | return newString; |
| 2579 | } |
| 2580 | |
| 2581 | /* Record the length as a prefix. |
| 2582 | */ |
no test coverage detected