diff options
author | Alan Modra <amodra@gmail.com> | 2019-12-18 15:37:44 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2019-12-18 18:38:13 +1030 |
commit | 2480b6fa946bb2d2dc993b1c4a83a8e1258a75e8 (patch) | |
tree | ce542aad0a4875a62960e77e23c4729b92d87da4 /opcodes/arc-ext.c | |
parent | 4a422785822ec9302f681c8fbc6ba2cc35231b09 (diff) | |
download | gdb-2480b6fa946bb2d2dc993b1c4a83a8e1258a75e8.zip gdb-2480b6fa946bb2d2dc993b1c4a83a8e1258a75e8.tar.gz gdb-2480b6fa946bb2d2dc993b1c4a83a8e1258a75e8.tar.bz2 |
More signed overflow fixes
The arc fix in create_map avoiding signed overflow by casting an
unsigned char to unsigned int before shifting, shows one of the
dangers of blinding doing that. The problem in this case was that the
variable storing the value, newAuxRegister->address, was a long.
Using the unsigned cast meant that the 32-bit value was zero extended
when long is 64 bits. Previously we had a sign extension. Net result
was that comparisons in arcExtMap_auxRegName didn't match. Of course,
I could have cast the 32-bit unsigned value back to signed before
storing in a long, but it's neater to just use an unsigned int for the
address.
opcodes/
* alpha-opc.c (OP): Avoid signed overflow.
* arm-dis.c (print_insn): Likewise.
* mcore-dis.c (print_insn_mcore): Likewise.
* pj-dis.c (get_int): Likewise.
* ppc-opc.c (EBD15, EBD15BI): Likewise.
* score7-dis.c (s7_print_insn): Likewise.
* tic30-dis.c (print_insn_tic30): Likewise.
* v850-opc.c (insert_SELID): Likewise.
* vax-dis.c (print_insn_vax): Likewise.
* arc-ext.c (create_map): Likewise.
(struct ExtAuxRegister): Make "address" field unsigned int.
(arcExtMap_auxRegName): Pass unsigned address.
(dump_ARC_extmap): Adjust.
* arc-ext.h (arcExtMap_auxRegName): Update prototype.
Diffstat (limited to 'opcodes/arc-ext.c')
-rw-r--r-- | opcodes/arc-ext.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/opcodes/arc-ext.c b/opcodes/arc-ext.c index cfb13aa..bc67668 100644 --- a/opcodes/arc-ext.c +++ b/opcodes/arc-ext.c @@ -53,7 +53,7 @@ struct ExtAuxRegister { - long address; + unsigned address; char * name; struct ExtAuxRegister * next; }; @@ -191,8 +191,8 @@ create_map (unsigned char *block, char *aux_name = xstrdup ((char *) (p + 6)); newAuxRegister->name = aux_name; - newAuxRegister->address = (p[2] << 24) | (p[3] << 16) - | (p[4] << 8) | p[5]; + newAuxRegister->address = (((unsigned) p[2] << 24) | (p[3] << 16) + | (p[4] << 8) | p[5]); newAuxRegister->next = arc_extension_map.auxRegisters; arc_extension_map.auxRegisters = newAuxRegister; break; @@ -406,7 +406,7 @@ arcExtMap_condCodeName (int code) /* Get the name of an extension auxiliary register. */ const char * -arcExtMap_auxRegName (long address) +arcExtMap_auxRegName (unsigned address) { /* Walk the list of auxiliary register names and find the name. */ struct ExtAuxRegister *r; @@ -463,7 +463,7 @@ dump_ARC_extmap (void) while (r) { - printf ("AUX : %s %ld\n", r->name, r->address); + printf ("AUX : %s %u\n", r->name, r->address); r = r->next; } |