MCPcopy Create free account
hub / github.com/PlayFab/gsdk / duplicateAndPrefixStringValue

Function duplicateAndPrefixStringValue

cpp/cppsdk/jsoncpp.cpp:2583–2602  ·  view source on GitHub ↗

Record the length as a prefix. */

Source from the content-addressed store, hash-verified

2581/* Record the length as a prefix.
2582 */
2583static inline char* duplicateAndPrefixStringValue(const char* value,
2584 unsigned int length) {
2585 // Avoid an integer overflow in the call to malloc below by limiting length
2586 // to a sane value.
2587 JSON_ASSERT_MESSAGE(length <= static_cast<unsigned>(Value::maxInt) -
2588 sizeof(unsigned) - 1U,
2589 "in Json::Value::duplicateAndPrefixStringValue(): "
2590 "length too big for prefixing");
2591 unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
2592 char* newString = static_cast<char*>(malloc(actualLength));
2593 if (newString == 0) {
2594 throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
2595 "Failed to allocate string value buffer");
2596 }
2597 *reinterpret_cast<unsigned*>(newString) = length;
2598 memcpy(newString + sizeof(unsigned), value, length);
2599 newString[actualLength - 1U] =
2600 0; // to avoid buffer over-run accidents by users later
2601 return newString;
2602}
2603inline static void decodePrefixedString(bool isPrefixed,
2604 char const* prefixed,
2605 unsigned* length,

Callers 2

ValueMethod · 0.85
dupPayloadMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected