MCPcopy Create free account
hub / github.com/SOUI2/soui / duplicateStringValue

Function duplicateStringValue

third-part/jsoncpp/src/lib_json/json_value.cpp:97–114  ·  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

95 * @return Pointer on the duplicate instance of string.
96 */
97static inline char* duplicateStringValue(const char* value,
98 size_t length)
99{
100 // Avoid an integer overflow in the call to malloc below by limiting length
101 // to a sane value.
102 if (length >= static_cast<size_t>(Value::maxInt))
103 length = Value::maxInt - 1;
104
105 char* newString = static_cast<char*>(malloc(length + 1));
106 if (newString == NULL) {
107 throwRuntimeError(
108 "in Json::Value::duplicateStringValue(): "
109 "Failed to allocate string value buffer");
110 }
111 memcpy(newString, value, length);
112 newString[length] = 0;
113 return newString;
114}
115
116/* Record the length as a prefix.
117 */

Callers 2

setCommentMethod · 0.85
CZStringMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected