MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / duplicateAndPrefixStringValue

Function duplicateAndPrefixStringValue

json/jsoncpp.cpp:2585–2604  ·  view source on GitHub ↗

Record the length as a prefix. */

Source from the content-addressed store, hash-verified

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

Callers 2

ValueMethod · 0.85
dupPayloadMethod · 0.85

Calls 1

throwRuntimeErrorFunction · 0.85

Tested by

no test coverage detected