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

Function duplicateAndPrefixStringValue

runtime/3rdparty/jsoncpp/jsoncpp.cpp:2775–2793  ·  view source on GitHub ↗

Record the length as a prefix. */

Source from the content-addressed store, hash-verified

2773/* Record the length as a prefix.
2774 */
2775static inline char *duplicateAndPrefixStringValue(const char *value, unsigned int length)
2776{
2777 // Avoid an integer overflow in the call to malloc below by limiting length
2778 // to a sane value.
2779 JSON_ASSERT_MESSAGE(length <= static_cast<unsigned>(Value::maxInt) - sizeof(unsigned) - 1U,
2780 "in Json::Value::duplicateAndPrefixStringValue(): "
2781 "length too big for prefixing");
2782 size_t actualLength = sizeof(length) + length + 1;
2783 auto newString = static_cast<char *>(malloc(actualLength));
2784 if (newString == nullptr)
2785 {
2786 throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
2787 "Failed to allocate string value buffer");
2788 }
2789 *reinterpret_cast<unsigned *>(newString) = length;
2790 memcpy(newString + sizeof(unsigned), value, length);
2791 newString[actualLength - 1U] = 0; // to avoid buffer over-run accidents by users later
2792 return newString;
2793}
2794inline static void decodePrefixedString(bool isPrefixed, char const *prefixed, unsigned *length,
2795 char const **value)
2796{

Callers 2

ValueMethod · 0.85
dupPayloadMethod · 0.85

Calls 2

mallocFunction · 0.85
throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected