Commit 561fe0f5 authored by Kenton Varda's avatar Kenton Varda

Fix fuzz test with -fno-exceptions.

parent 3e388975
...@@ -537,8 +537,9 @@ struct WireHelpers { ...@@ -537,8 +537,9 @@ struct WireHelpers {
return result; return result;
} }
static KJ_ALWAYS_INLINE(const word* followFars( static KJ_ALWAYS_INLINE(kj::Maybe<const word&> followFars(
const WirePointer*& ref, const word* refTarget, SegmentReader*& segment)) { const WirePointer*& ref, const word* refTarget, SegmentReader*& segment))
KJ_WARN_UNUSED_RESULT {
// Like the other followFars() but operates on readers. // Like the other followFars() but operates on readers.
// If the segment is null, this is an unchecked message, so there are no FAR pointers. // If the segment is null, this is an unchecked message, so there are no FAR pointers.
...@@ -582,6 +583,7 @@ struct WireHelpers { ...@@ -582,6 +583,7 @@ struct WireHelpers {
segment = newSegment; segment = newSegment;
return pad->farTarget(segment); return pad->farTarget(segment);
} else { } else {
KJ_DASSERT(refTarget != nullptr);
return refTarget; return refTarget;
} }
} }
...@@ -754,7 +756,12 @@ struct WireHelpers { ...@@ -754,7 +756,12 @@ struct WireHelpers {
} }
--nestingLimit; --nestingLimit;
const word* ptr = followFars(ref, ref->target(segment), segment); const word* ptr;
KJ_IF_MAYBE(p, followFars(ref, ref->target(segment), segment)) {
ptr = p;
} else {
return result;
}
switch (ref->kind()) { switch (ref->kind()) {
case WirePointer::STRUCT: { case WirePointer::STRUCT: {
...@@ -1918,9 +1925,10 @@ struct WireHelpers { ...@@ -1918,9 +1925,10 @@ struct WireHelpers {
return { dstSegment, nullptr }; return { dstSegment, nullptr };
} }
const word* ptr = WireHelpers::followFars(src, srcTarget, srcSegment); const word* ptr;
if (KJ_UNLIKELY(ptr == nullptr)) { KJ_IF_MAYBE(p, WireHelpers::followFars(src, srcTarget, srcSegment)) {
// Already reported the error. ptr = p;
} else {
goto useDefault; goto useDefault;
} }
...@@ -2135,9 +2143,10 @@ struct WireHelpers { ...@@ -2135,9 +2143,10 @@ struct WireHelpers {
goto useDefault; goto useDefault;
} }
const word* ptr = followFars(ref, refTarget, segment); const word* ptr;
if (KJ_UNLIKELY(ptr == nullptr)) { KJ_IF_MAYBE(p, followFars(ref, refTarget, segment)) {
// Already reported the error. ptr = p;
} else {
goto useDefault; goto useDefault;
} }
...@@ -2220,9 +2229,10 @@ struct WireHelpers { ...@@ -2220,9 +2229,10 @@ struct WireHelpers {
goto useDefault; goto useDefault;
} }
const word* ptr = followFars(ref, refTarget, segment); const word* ptr;
if (KJ_UNLIKELY(ptr == nullptr)) { KJ_IF_MAYBE(p, followFars(ref, refTarget, segment)) {
// Already reported error. ptr = p;
} else {
goto useDefault; goto useDefault;
} }
...@@ -2390,10 +2400,10 @@ struct WireHelpers { ...@@ -2390,10 +2400,10 @@ struct WireHelpers {
return Text::Reader(reinterpret_cast<const char*>(defaultValue), return Text::Reader(reinterpret_cast<const char*>(defaultValue),
unbound(defaultSize / BYTES)); unbound(defaultSize / BYTES));
} else { } else {
const word* ptr = followFars(ref, refTarget, segment); const word* ptr;
KJ_IF_MAYBE(p, followFars(ref, refTarget, segment)) {
if (KJ_UNLIKELY(ptr == nullptr)) { ptr = p;
// Already reported error. } else {
goto useDefault; goto useDefault;
} }
...@@ -2443,7 +2453,12 @@ struct WireHelpers { ...@@ -2443,7 +2453,12 @@ struct WireHelpers {
return Data::Reader(reinterpret_cast<const byte*>(defaultValue), return Data::Reader(reinterpret_cast<const byte*>(defaultValue),
unbound(defaultSize / BYTES)); unbound(defaultSize / BYTES));
} else { } else {
const word* ptr = followFars(ref, refTarget, segment); const word* ptr;
KJ_IF_MAYBE(p, followFars(ref, refTarget, segment)) {
ptr = p;
} else {
goto useDefault;
}
if (KJ_UNLIKELY(ptr == nullptr)) { if (KJ_UNLIKELY(ptr == nullptr)) {
// Already reported error. // Already reported error.
...@@ -2694,10 +2709,10 @@ PointerType PointerReader::getPointerType() const { ...@@ -2694,10 +2709,10 @@ PointerType PointerReader::getPointerType() const {
if(pointer == nullptr || pointer->isNull()) { if(pointer == nullptr || pointer->isNull()) {
return PointerType::NULL_; return PointerType::NULL_;
} else { } else {
word* refTarget = nullptr;
const WirePointer* ptr = pointer; const WirePointer* ptr = pointer;
const word* refTarget = ptr->target(segment);
SegmentReader* sgmt = segment; SegmentReader* sgmt = segment;
WireHelpers::followFars(ptr, refTarget, sgmt); if (WireHelpers::followFars(ptr, refTarget, sgmt) == nullptr) return PointerType::NULL_;
switch(ptr->kind()) { switch(ptr->kind()) {
case WirePointer::FAR: case WirePointer::FAR:
KJ_FAIL_ASSERT("far pointer not followed?") { return PointerType::NULL_; } KJ_FAIL_ASSERT("far pointer not followed?") { return PointerType::NULL_; }
......
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