Commit f2f376a9 authored by David Renshaw's avatar David Renshaw

fix some but not all errors reported by -DCAPNP_DEBUG_TYPES

parent fbb5f0f1
...@@ -1812,13 +1812,14 @@ struct WireHelpers { ...@@ -1812,13 +1812,14 @@ struct WireHelpers {
// List of data. // List of data.
ref->listRef.set(value.elementSize, value.elementCount); ref->listRef.set(value.elementSize, value.elementCount);
auto wholeByteSize = value.elementCount * value.step / BITS_PER_BYTE; auto wholeByteSize = upgradeBound<uint64_t>(value.elementCount) * value.step / BITS_PER_BYTE;
copyMemory(reinterpret_cast<byte*>(ptr), value.ptr, wholeByteSize); copyMemory(reinterpret_cast<byte*>(ptr), value.ptr, wholeByteSize);
auto leftoverBits = value.elementCount * value.step % BITS_PER_BYTE; auto leftoverBits =
if (leftoverBits > 0) { (upgradeBound<uint64_t>(value.elementCount) * value.step) % (BYTES * BITS_PER_BYTE);
if (leftoverBits > ZERO * BITS) {
// We need to copy a partial byte. // We need to copy a partial byte.
uint8_t mask = (1 << leftoverBits) - 1; uint8_t mask = (1 << leftoverBits / BITS) - 1;
(reinterpret_cast<byte*>(ptr))[wholeByteSize] = mask & value.ptr[wholeByteSize]; *((reinterpret_cast<byte*>(ptr)) + wholeByteSize) = mask & *(value.ptr + wholeByteSize);
} }
} }
...@@ -3162,9 +3163,10 @@ bool ListReader::isCanonical(const word **readHead, const WirePointer *ref) { ...@@ -3162,9 +3163,10 @@ bool ListReader::isCanonical(const word **readHead, const WirePointer *ref) {
auto byteReadHead = reinterpret_cast<const uint8_t*>(*readHead) + truncatedByteSize; auto byteReadHead = reinterpret_cast<const uint8_t*>(*readHead) + truncatedByteSize;
auto readHeadEnd = *readHead + WireHelpers::roundBitsUpToWords(bitSize); auto readHeadEnd = *readHead + WireHelpers::roundBitsUpToWords(bitSize);
auto leftoverBits = bitSize % 8; auto leftoverBits = bitSize % (BYTES * BITS_PER_BYTE);
if (leftoverBits > 0) { if (leftoverBits > ZERO * BITS) {
uint8_t mask = ~((1 << leftoverBits) - 1); auto mask = ~((1 << (leftoverBits / BITS)) - 1);
if (mask & *byteReadHead) { if (mask & *byteReadHead) {
return false; return false;
} }
......
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