jwnhy created this revision. jwnhy added reviewers: clayborg, jingham. Herald added a project: All. jwnhy requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
As described in #61706 <https://github.com/llvm/llvm-project/issues/61706>, the `ValueObjectChild::UpdateValue(...)` may underflow the unsigned `m_bitfield_bit_offset`. This is due to that in `ValueObjectChild::UpdateValue(...)`, the moved `overhang_bytes` only considers the `bitfield_end - *type_bit_size`. However, under certain cases, the `m_bitfield_bit_offset` may not strictly aligned to `*type_bit_size`, e.g. 27 < 32. This results 27 - 32 = -5 underflows the unsigned `uint8_t m_bitfield_bit_offset`. This patch fixes this issue by setting the `overhang_bytes` to the smaller value between `bitfield_end - *type_bit_size` and `m_bitfield_bit_offset` to avoid underflow. I am quite new to this community, any helps/guidance are much appreciated. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D146919 Files: lldb/source/Core/ValueObjectChild.cpp Index: lldb/source/Core/ValueObjectChild.cpp =================================================================== --- lldb/source/Core/ValueObjectChild.cpp +++ lldb/source/Core/ValueObjectChild.cpp @@ -170,6 +170,8 @@ if (bitfield_end > *type_bit_size) { uint64_t overhang_bytes = (bitfield_end - *type_bit_size + 7) / 8; + if (overhang_bytes > m_bitfield_bit_offset / 8) + overhang_bytes = m_bitfield_bit_offset / 8; m_byte_offset += overhang_bytes; m_bitfield_bit_offset -= overhang_bytes * 8; }
Index: lldb/source/Core/ValueObjectChild.cpp =================================================================== --- lldb/source/Core/ValueObjectChild.cpp +++ lldb/source/Core/ValueObjectChild.cpp @@ -170,6 +170,8 @@ if (bitfield_end > *type_bit_size) { uint64_t overhang_bytes = (bitfield_end - *type_bit_size + 7) / 8; + if (overhang_bytes > m_bitfield_bit_offset / 8) + overhang_bytes = m_bitfield_bit_offset / 8; m_byte_offset += overhang_bytes; m_bitfield_bit_offset -= overhang_bytes * 8; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits