From 55f79ae7068d292e5e957d2194b756bbc87e7af4 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Thu, 2 Aug 2018 15:21:37 -0700 Subject: Fix incorrect left shifts. Bug: 112142060 Test: New unit tests pass. Change-Id: I0c47b22582f0bf75ab503364a337c7de4de3ec43 --- libunwindstack/RegsInfo.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libunwindstack/RegsInfo.h') diff --git a/libunwindstack/RegsInfo.h b/libunwindstack/RegsInfo.h index 47825f5..e6dd33c 100644 --- a/libunwindstack/RegsInfo.h +++ b/libunwindstack/RegsInfo.h @@ -25,11 +25,13 @@ namespace unwindstack { template struct RegsInfo { + static constexpr size_t MAX_REGISTERS = 64; + RegsInfo(RegsImpl* regs) : regs(regs) {} RegsImpl* regs = nullptr; uint64_t saved_reg_map = 0; - AddressType saved_regs[64]; + AddressType saved_regs[MAX_REGISTERS]; inline AddressType Get(uint32_t reg) { if (IsSaved(reg)) { @@ -39,23 +41,23 @@ struct RegsInfo { } inline AddressType* Save(uint32_t reg) { - if (reg > sizeof(saved_regs) / sizeof(AddressType)) { - // This should never happen as since all currently supported - // architectures have the total number of registers < 64. + if (reg > MAX_REGISTERS) { + // This should never happen since all currently supported + // architectures have < 64 total registers. abort(); } - saved_reg_map |= 1 << reg; + saved_reg_map |= 1ULL << reg; saved_regs[reg] = (*regs)[reg]; return &(*regs)[reg]; } inline bool IsSaved(uint32_t reg) { - if (reg > sizeof(saved_regs) / sizeof(AddressType)) { - // This should never happen as since all currently supported - // architectures have the total number of registers < 64. + if (reg > MAX_REGISTERS) { + // This should never happen since all currently supported + // architectures have < 64 total registers. abort(); } - return saved_reg_map & (1 << reg); + return saved_reg_map & (1ULL << reg); } inline uint16_t Total() { return regs->total_regs(); } -- cgit v1.2.3