MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / duplicateStringValue

Function duplicateStringValue

src/share/jsoncpp/jsoncpp.cpp:2545–2562  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

2543 * @return Pointer on the duplicate instance of string.
2544 */
2545static inline char* duplicateStringValue(const char* value,
2546 size_t length)
2547{
2548 // Avoid an integer overflow in the call to malloc below by limiting length
2549 // to a sane value.
2550 if (length >= static_cast<size_t>(Value::maxInt))
2551 length = Value::maxInt - 1;
2552
2553 char* newString = static_cast<char*>(malloc(length + 1));
2554 if (newString == NULL) {
2555 throwRuntimeError(
2556 "in Json::Value::duplicateStringValue(): "
2557 "Failed to allocate string value buffer");
2558 }
2559 memcpy(newString, value, length);
2560 newString[length] = 0;
2561 return newString;
2562}
2563
2564/* Record the length as a prefix.
2565 */

Callers 2

setCommentMethod · 0.85
CZStringMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected