Bugfix: offsetting hasbits with 16 introduced a bug in calculating

hasmasks. Removing extra <<16 shift in hasmask calculating and masking
out the first 16 bits. This makes messages without hasbits work as well.
pull/13171/head
Gerben Stavenga 4 years ago
parent 4053805759
commit 3f719fa6b2
  1. 10
      upbc/generator.cc

@ -790,13 +790,13 @@ void TryFillTableEntry(const protobuf::Descriptor* message,
uint16_t expected_tag = (num << 3) | wire_type;
if (num > 15) expected_tag |= 0x100;
MessageLayout::Size offset = layout.GetFieldOffset(field);
uint64_t hasbit_index = 0;
uint64_t hasbit_index = 0; // Zero means no hasbits.
if (layout.HasHasbit(field)) {
hasbit_index = layout.GetHasbitIndex(field);
if (hasbit_index > 31) return;
// thas hasbits mask in the parser occupies bits 16-48
// in the 64 bit register.
// in the 64 bit register.
hasbit_index += 16; // account for the shifted hasbits
}
@ -811,9 +811,9 @@ void TryFillTableEntry(const protobuf::Descriptor* message,
data.size32 |= idx << 16 | hasbit_index << 32;
data.size64 |= idx << 16 | hasbit_index << 32;
} else {
uint32_t hasbit_mask = 1U << hasbit_index;
data.size32 |= (uint64_t)hasbit_mask << 16;
data.size64 |= (uint64_t)hasbit_mask << 16;
uint64_t hasbit_mask = (1ull << hasbit_index) & -0x10000;
data.size32 |= (uint64_t)hasbit_mask;
data.size64 |= (uint64_t)hasbit_mask;
}

Loading…
Cancel
Save