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

Function duplicateAndPrefixStringValue

vrclient_x64/jsoncpp.cpp:2539–2559  ·  view source on GitHub ↗

Record the length as a prefix. */

Source from the content-addressed store, hash-verified

2537/* Record the length as a prefix.
2538 */
2539static inline char* duplicateAndPrefixStringValue(
2540 const char* value,
2541 unsigned int length)
2542{
2543 // Avoid an integer overflow in the call to malloc below by limiting length
2544 // to a sane value.
2545 JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
2546 "in Json::Value::duplicateAndPrefixStringValue(): "
2547 "length too big for prefixing");
2548 unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
2549 char* newString = static_cast<char*>(malloc(actualLength));
2550 if (newString == 0) {
2551 throwRuntimeError(
2552 "in Json::Value::duplicateAndPrefixStringValue(): "
2553 "Failed to allocate string value buffer");
2554 }
2555 *reinterpret_cast<unsigned*>(newString) = length;
2556 memcpy(newString + sizeof(unsigned), value, length);
2557 newString[actualLength - 1U] = 0; // to avoid buffer over-run accidents by users later
2558 return newString;
2559}
2560inline static void decodePrefixedString(
2561 bool isPrefixed, char const* prefixed,
2562 unsigned* length, char const** value)

Callers 1

ValueMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected