MCPcopy Create free account
hub / github.com/ValveSoftware/Proton / duplicateStringValue

Function duplicateStringValue

vrclient_x64/jsoncpp.cpp:2519–2535  ·  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

2517 * @return Pointer on the duplicate instance of string.
2518 */
2519static inline char* duplicateStringValue(const char* value,
2520 size_t length) {
2521 // Avoid an integer overflow in the call to malloc below by limiting length
2522 // to a sane value.
2523 if (length >= (size_t)Value::maxInt)
2524 length = Value::maxInt - 1;
2525
2526 char* newString = static_cast<char*>(malloc(length + 1));
2527 if (newString == NULL) {
2528 throwRuntimeError(
2529 "in Json::Value::duplicateStringValue(): "
2530 "Failed to allocate string value buffer");
2531 }
2532 memcpy(newString, value, length);
2533 newString[length] = 0;
2534 return newString;
2535}
2536
2537/* Record the length as a prefix.
2538 */

Callers 2

setCommentMethod · 0.85
CZStringMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected