MCPcopy Create free account
hub / github.com/Samsung/UTopia / duplicateAndPrefixStringValue

Function duplicateAndPrefixStringValue

external/jsoncpp/jsoncpp.cpp:2532–2551  ·  view source on GitHub ↗

Record the length as a prefix. */

Source from the content-addressed store, hash-verified

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

Callers 2

ValueMethod · 0.85
dupPayloadMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected