MCPcopy Create free account
hub / github.com/Illumina/hap.py / duplicateStringValue

Function duplicateStringValue

external/jsoncpp/jsoncpp.cpp:1582–1599  ·  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

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

Callers 3

setCommentMethod · 0.85
CZStringMethod · 0.85
ValueMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected