Commit 7b6b7ae2 authored by Kenton Varda's avatar Kenton Varda

Fix build under CAPNP_DEBUG_TYPES.

parent 1f609e20
...@@ -242,8 +242,10 @@ MallocMessageBuilder::~MallocMessageBuilder() noexcept(false) { ...@@ -242,8 +242,10 @@ MallocMessageBuilder::~MallocMessageBuilder() noexcept(false) {
} }
kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) { kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) {
KJ_REQUIRE(minimumSize <= MAX_SEGMENT_WORDS, "MallocMessageBuilder asked to allocate segment above maximum serializable size."); KJ_REQUIRE(bounded(minimumSize) * WORDS <= MAX_SEGMENT_WORDS,
KJ_ASSERT(nextSize <= MAX_SEGMENT_WORDS, "MallocMessageBuilder nextSize out of bounds."); "MallocMessageBuilder asked to allocate segment above maximum serializable size.");
KJ_ASSERT(bounded(nextSize) * WORDS <= MAX_SEGMENT_WORDS,
"MallocMessageBuilder nextSize out of bounds.");
if (!returnedFirstSegment && !ownFirstSegment) { if (!returnedFirstSegment && !ownFirstSegment) {
kj::ArrayPtr<word> result = kj::arrayPtr(reinterpret_cast<word*>(firstSegment), nextSize); kj::ArrayPtr<word> result = kj::arrayPtr(reinterpret_cast<word*>(firstSegment), nextSize);
...@@ -283,7 +285,8 @@ kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) { ...@@ -283,7 +285,8 @@ kj::ArrayPtr<word> MallocMessageBuilder::allocateSegment(uint minimumSize) {
if (allocationStrategy == AllocationStrategy::GROW_HEURISTICALLY) { if (allocationStrategy == AllocationStrategy::GROW_HEURISTICALLY) {
// set nextSize = min(nextSize+size, MAX_SEGMENT_WORDS) // set nextSize = min(nextSize+size, MAX_SEGMENT_WORDS)
// while protecting against possible overflow of (nextSize+size) // while protecting against possible overflow of (nextSize+size)
nextSize = (size <= MAX_SEGMENT_WORDS-nextSize) ? nextSize+size : MAX_SEGMENT_WORDS; nextSize = (size <= unbound(MAX_SEGMENT_WORDS / WORDS) - nextSize)
? nextSize + size : unbound(MAX_SEGMENT_WORDS / WORDS);
} }
} }
......
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