MCPcopy Create free account
hub / github.com/Kitware/CMake / duplicateStringValue

Function duplicateStringValue

Utilities/cmjsoncpp/src/lib_json/json_value.cpp:115–129  ·  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

113 * @return Pointer on the duplicate instance of string.
114 */
115static inline char* duplicateStringValue(const char* value, size_t length) {
116 // Avoid an integer overflow in the call to malloc below by limiting length
117 // to a sane value.
118 if (length >= static_cast<size_t>(Value::maxInt))
119 length = Value::maxInt - 1;
120
121 auto newString = static_cast<char*>(malloc(length + 1));
122 if (newString == nullptr) {
123 throwRuntimeError("in Json::Value::duplicateStringValue(): "
124 "Failed to allocate string value buffer");
125 }
126 memcpy(newString, value, length);
127 newString[length] = 0;
128 return newString;
129}
130
131/* Record the length as a prefix.
132 */

Callers 1

CZStringMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…