]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Avoid undefined behavior in read_subrange_type
authorTom Tromey <tom@tromey.com>
Sun, 29 Jul 2018 23:29:24 +0000 (17:29 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 3 Oct 2018 21:19:06 +0000 (15:19 -0600)
-fsanitize=undefined pointed out an undefined shift of a negative
value in read_subrange_type.  The fix is to do the work in an unsigned
type, where this is defined.

gdb/ChangeLog
2018-10-03  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (read_subrange_type): Make "negative_mask"
unsigned.

gdb/ChangeLog
gdb/dwarf2read.c

index 5787d44424facdd6d1b25a8c6bd831385fd52256..4be30330e59012793d81754cb3b9b83b26b09c0f 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-03  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2read.c (read_subrange_type): Make "negative_mask"
+       unsigned.
+
 2018-10-03  Tom Tromey  <tom@tromey.com>
 
        * findvar.c (extract_integer): Do work in an unsigned type.
index 4a35e389e9384be3a2a77b5c0251b5707ac457a4..4013c199dad91d95ca634aa00b178ae7699ee58f 100644 (file)
@@ -17709,7 +17709,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   int low_default_is_valid;
   int high_bound_is_count = 0;
   const char *name;
-  LONGEST negative_mask;
+  ULONGEST negative_mask;
 
   orig_base_type = die_type (die, cu);
   /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
@@ -17842,7 +17842,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the bounds as signed, and thus sign-extend their values, when
      the base type is signed.  */
   negative_mask =
-    -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
+    -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
   if (low.kind == PROP_CONST
       && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
     low.data.const_val |= negative_mask;