[PATCH] libdwfl: __libdwfl_frame_reg_[gs]et use uint64_t when checking bits.

Mark Wielaard mjw at redhat.com
Tue Apr 22 21:58:45 UTC 2014


Found by gcc -fsanitize=undefined while running the backtrace-core-ppc test.
runtime error: shift exponent 45 is too large for 32-bit type 'unsigned int'

Signed-off-by: Mark Wielaard <mjw at redhat.com>
---
 libdwfl/ChangeLog      |    6 ++++++
 libdwfl/frame_unwind.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index e93d50c..31697ce 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2014-04-22  Mark Wielaard  <mjw at redhat.com>
+
+	* frame_unwind.c (__libdwfl_frame_reg_get): Use uint64_t when
+	checking bits.
+	(__libdwfl_frame_reg_set): Likewise.
+
 2014-03-14  Mark Wielaard  <mjw at redhat.com>
 
 	* Makefile.am: Remove !MUDFLAP and MUDFLAP conditions.
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index dc99e40..18c808b 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -57,7 +57,7 @@ __libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno, Dwarf_Addr *val)
   if (regno >= ebl_frame_nregs (ebl))
     return false;
   if ((state->regs_set[regno / sizeof (*state->regs_set) / 8]
-       & (1U << (regno % (sizeof (*state->regs_set) * 8)))) == 0)
+       & ((uint64_t) 1U << (regno % (sizeof (*state->regs_set) * 8)))) == 0)
     return false;
   if (val)
     *val = state->regs[regno];
@@ -77,7 +77,7 @@ __libdwfl_frame_reg_set (Dwfl_Frame *state, unsigned regno, Dwarf_Addr val)
   if (ebl_get_elfclass (ebl) == ELFCLASS32)
     val &= 0xffffffff;
   state->regs_set[regno / sizeof (*state->regs_set) / 8] |=
-			      (1U << (regno % (sizeof (*state->regs_set) * 8)));
+		((uint64_t) 1U << (regno % (sizeof (*state->regs_set) * 8)));
   state->regs[regno] = val;
   return true;
 }
-- 
1.7.1



More information about the elfutils-devel mailing list