MCPcopy Create free account
hub / github.com/cinder/Cinder / duplicateStringValue

Function duplicateStringValue

src/jsoncpp/jsoncpp.cpp:1574–1591  ·  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

1572 * @return Pointer on the duplicate instance of string.
1573 */
1574static inline char* duplicateStringValue(const char* value,
1575 unsigned int length = unknown) {
1576 if (length == unknown)
1577 length = (unsigned int)strlen(value);
1578
1579 // Avoid an integer overflow in the call to malloc below by limiting length
1580 // to a sane value.
1581 if (length >= (unsigned)Value::maxInt)
1582 length = Value::maxInt - 1;
1583
1584 char* newString = static_cast<char*>(malloc(length + 1));
1585 JSON_ASSERT_MESSAGE(newString != 0,
1586 "in Json::Value::duplicateStringValue(): "
1587 "Failed to allocate string value buffer");
1588 memcpy(newString, value, length);
1589 newString[length] = 0;
1590 return newString;
1591}
1592
1593/** Free the string duplicated by duplicateStringValue().
1594 */

Callers 3

setCommentMethod · 0.85
CZStringMethod · 0.85
ValueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected