aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-07-29 17:29:24 -0600
committerTom Tromey <tom@tromey.com>2018-10-03 15:19:06 -0600
commitd359392f976d48b04a27e6a09b5b61846b0727f9 (patch)
tree06193527ab4d4a21de1ffc377ea23d7243d800fc /gdb
parent0101665f864383147448c5871a67286a3f7a9a28 (diff)
downloadgdb-d359392f976d48b04a27e6a09b5b61846b0727f9.zip
gdb-d359392f976d48b04a27e6a09b5b61846b0727f9.tar.gz
gdb-d359392f976d48b04a27e6a09b5b61846b0727f9.tar.bz2
Avoid undefined behavior in read_subrange_type
-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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2read.c4
2 files changed, 7 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5787d44..4be3033 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
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.
2018-10-03 Tom Tromey <tom@tromey.com>
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4a35e38..4013c19 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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;