diff mbox

[v2,3/4] Use unsigned integer constant with left shifts.

Message ID 20160701174036.90598-4-jhb@FreeBSD.org
State New
Headers show

Commit Message

John Baldwin July 1, 2016, 5:40 p.m. UTC
This avoids undefined behavior.

gdb/ChangeLog:

	* ada-lang.c (ada_unpack_from_contents): Use unsigned constants with
	left shifts.
---
 gdb/ChangeLog  | 5 +++++
 gdb/ada-lang.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Yao Qi July 6, 2016, 8:03 a.m. UTC | #1
On Fri, Jul 1, 2016 at 6:40 PM, John Baldwin <jhb@freebsd.org> wrote:
> This avoids undefined behavior.
>
> gdb/ChangeLog:
>
>         * ada-lang.c (ada_unpack_from_contents): Use unsigned constants with
>         left shifts.

Patch is good to me.
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 727cf37..97db7ef 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2016-07-01  John Baldwin  <jhb@FreeBSD.org>
 
+	* ada-lang.c (ada_unpack_from_contents): Use unsigned constants with
+	left shifts.
+
+2016-07-01  John Baldwin  <jhb@FreeBSD.org>
+
 	* sh64-tdep.c (sh64_analyze_prologue): Set "uses_fp" when setting
 	the MEDIA_FP_REGNUM register.
 
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b22b7ac..05bfd7b 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2525,7 +2525,7 @@  ada_unpack_from_contents (const gdb_byte *src, int bit_offset, int bit_size,
       accumSize += HOST_CHAR_BIT - unusedLS;
       if (accumSize >= HOST_CHAR_BIT)
         {
-          unpacked[unpacked_idx] = accum & ~(~0L << HOST_CHAR_BIT);
+          unpacked[unpacked_idx] = accum & ~(~0UL << HOST_CHAR_BIT);
           accumSize -= HOST_CHAR_BIT;
           accum >>= HOST_CHAR_BIT;
           unpacked_bytes_left -= 1;
@@ -2539,7 +2539,7 @@  ada_unpack_from_contents (const gdb_byte *src, int bit_offset, int bit_size,
   while (unpacked_bytes_left > 0)
     {
       accum |= sign << accumSize;
-      unpacked[unpacked_idx] = accum & ~(~0L << HOST_CHAR_BIT);
+      unpacked[unpacked_idx] = accum & ~(~0UL << HOST_CHAR_BIT);
       accumSize -= HOST_CHAR_BIT;
       if (accumSize < 0)
 	accumSize = 0;