From 3f719fa6b2ee842f4d97d9a5b903433235e05123 Mon Sep 17 00:00:00 2001 From: Gerben Stavenga Date: Mon, 12 Oct 2020 00:08:44 -0700 Subject: [PATCH] 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. --- upbc/generator.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upbc/generator.cc b/upbc/generator.cc index 71dc7adcfa..52cfb30cf4 100644 --- a/upbc/generator.cc +++ b/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; }