Commit 26bcceda authored by Kenton Varda's avatar Kenton Varda
parent f343f0db
...@@ -1430,6 +1430,7 @@ struct WireHelpers { ...@@ -1430,6 +1430,7 @@ struct WireHelpers {
WirePointer* ref, word* refTarget, SegmentBuilder* segment, WirePointer* ref, word* refTarget, SegmentBuilder* segment,
const void* defaultValue, ByteCount defaultSize)) { const void* defaultValue, ByteCount defaultSize)) {
if (ref->isNull()) { if (ref->isNull()) {
useDefault:
if (defaultSize == 0 * BYTES) { if (defaultSize == 0 * BYTES) {
return nullptr; return nullptr;
} else { } else {
...@@ -1439,14 +1440,19 @@ struct WireHelpers { ...@@ -1439,14 +1440,19 @@ struct WireHelpers {
} }
} else { } else {
word* ptr = followFars(ref, refTarget, segment); word* ptr = followFars(ref, refTarget, segment);
char* cptr = reinterpret_cast<char*>(ptr);
KJ_REQUIRE(ref->kind() == WirePointer::LIST, KJ_REQUIRE(ref->kind() == WirePointer::LIST,
"Called getText{Field,Element}() but existing pointer is not a list."); "Called getText{Field,Element}() but existing pointer is not a list.");
KJ_REQUIRE(ref->listRef.elementSize() == ElementSize::BYTE, KJ_REQUIRE(ref->listRef.elementSize() == ElementSize::BYTE,
"Called getText{Field,Element}() but existing list pointer is not byte-sized."); "Called getText{Field,Element}() but existing list pointer is not byte-sized.");
// Subtract 1 from the size for the NUL terminator. size_t size = ref->listRef.elementCount() / ELEMENTS;
return Text::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS - 1); KJ_REQUIRE(size > 0 && cptr[size-1] == '\0', "Text blob missing NUL terminator.") {
goto useDefault;
}
return Text::Builder(cptr, size - 1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment