diff options
author | Alan Modra <amodra@gmail.com> | 2020-01-13 10:46:55 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-01-13 12:12:30 +1030 |
commit | b2c759ce68102931140ce34c2ac00619ba363622 (patch) | |
tree | ac4f7a6f709927a91d8be9ed67c385ecf6cf1711 | |
parent | b50ef514ff0c8d5506227c412c508f9f538bcf5a (diff) | |
download | gdb-b2c759ce68102931140ce34c2ac00619ba363622.zip gdb-b2c759ce68102931140ce34c2ac00619ba363622.tar.gz gdb-b2c759ce68102931140ce34c2ac00619ba363622.tar.bz2 |
ubsan: score: left shift of negative value
* score-dis.c (print_insn_score48): Use unsigned variables for
unsigned values. Don't left shift negative values.
(print_insn_score32): Likewise.
* score7-dis.c (print_insn_score32, print_insn_score16): Likewise.
-rw-r--r-- | opcodes/ChangeLog | 7 | ||||
-rw-r--r-- | opcodes/score-dis.c | 20 | ||||
-rw-r--r-- | opcodes/score7-dis.c | 28 |
3 files changed, 31 insertions, 24 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 26d1e6c..4740186 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,5 +1,12 @@ 2020-01-13 Alan Modra <amodra@gmail.com> + * score-dis.c (print_insn_score48): Use unsigned variables for + unsigned values. Don't left shift negative values. + (print_insn_score32): Likewise. + * score7-dis.c (print_insn_score32, print_insn_score16): Likewise. + +2020-01-13 Alan Modra <amodra@gmail.com> + * tic4x-dis.c (tic4x_print_register): Remove dead code. 2020-01-13 Alan Modra <amodra@gmail.com> diff --git a/opcodes/score-dis.c b/opcodes/score-dis.c index 6b98a33..6f37dfd 100644 --- a/opcodes/score-dis.c +++ b/opcodes/score-dis.c @@ -565,7 +565,7 @@ print_insn_score48 (struct disassemble_info *info, bfd_vma given) { case 'r': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; @@ -575,7 +575,7 @@ print_insn_score48 (struct disassemble_info *info, bfd_vma given) break; case 'd': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; @@ -600,14 +600,14 @@ print_insn_score48 (struct disassemble_info *info, bfd_vma given) || ((given & insn->mask) == 0x0c00000b) /* stc1 */ || ((given & insn->mask) == 0x0c000013) /* stc2 */ || ((given & insn->mask) == 0x0c00001b)) /* stc3 */ - reg <<= 2; + reg *= 4; func (stream, "%ld", reg); } break; case 'x': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; @@ -617,7 +617,7 @@ print_insn_score48 (struct disassemble_info *info, bfd_vma given) break; case 'w': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; reg <<= 2; @@ -731,7 +731,7 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) } else { - long reg; + unsigned long reg; int bitstart = 10; int bitend = 14; reg = given >> bitstart; @@ -784,7 +784,7 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) { case 'r': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; @@ -794,7 +794,7 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) break; case 'd': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; @@ -817,14 +817,14 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) || ((given & insn->mask) == 0x0c00000b) /* stc1 */ || ((given & insn->mask) == 0x0c000013) /* stc2 */ || ((given & insn->mask) == 0x0c00001b)) /* stc3 */ - reg <<= 2; + reg *= 4; func (stream, "%ld", reg); } break; case 'x': { - long reg; + unsigned long reg; reg = given >> bitstart; reg &= (2u << (bitend - bitstart)) - 1; diff --git a/opcodes/score7-dis.c b/opcodes/score7-dis.c index b1b7734..c9b235b 100644 --- a/opcodes/score7-dis.c +++ b/opcodes/score7-dis.c @@ -613,20 +613,20 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) { case 'r': { - long reg; + unsigned long reg; reg = given >> bitstart; - reg &= (2 << (bitend - bitstart)) - 1; + reg &= (2u << (bitend - bitstart)) - 1; func (stream, "%s", score_regnames[reg]); } break; case 'd': { - long reg; + unsigned long reg; reg = given >> bitstart; - reg &= (2 << (bitend - bitstart)) - 1; + reg &= (2u << (bitend - bitstart)) - 1; func (stream, "%ld", reg); } @@ -636,9 +636,9 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) long reg; reg = given >> bitstart; - reg &= (2 << (bitend - bitstart)) - 1; - reg = ((reg ^ (1 << (bitend - bitstart))) - - (1 << (bitend - bitstart))); + reg &= (2u << (bitend - bitstart)) - 1; + reg = ((reg ^ (1 << (bitend - bitstart))) + - (1 << (bitend - bitstart))); if (((given & insn->mask) == 0x0c00000a) /* ldc1 */ || ((given & insn->mask) == 0x0c000012) /* ldc2 */ @@ -646,17 +646,17 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) || ((given & insn->mask) == 0x0c00000b) /* stc1 */ || ((given & insn->mask) == 0x0c000013) /* stc2 */ || ((given & insn->mask) == 0x0c00001b)) /* stc3 */ - reg <<= 2; + reg *= 4; func (stream, "%ld", reg); } break; case 'x': { - long reg; + unsigned long reg; reg = given >> bitstart; - reg &= (2 << (bitend - bitstart)) - 1; + reg &= (2u << (bitend - bitstart)) - 1; func (stream, "%lx", reg); } @@ -667,12 +667,12 @@ print_insn_score32 (bfd_vma pc, struct disassemble_info *info, long given) break; case '`': c++; - if ((given & (1 << bitstart)) == 0) + if ((given & (1u << bitstart)) == 0) func (stream, "%c", *c); break; case '\'': c++; - if ((given & (1 << bitstart)) != 0) + if ((given & (1u << bitstart)) != 0) func (stream, "%c", *c); break; default: @@ -789,7 +789,7 @@ print_insn_score16 (bfd_vma pc, struct disassemble_info *info, long given) if (!bitend) abort (); reg = given >> bitstart; - reg &= (2 << (bitend - bitstart)) - 1; + reg &= (2u << (bitend - bitstart)) - 1; switch (*c) { case 'R': @@ -835,7 +835,7 @@ print_insn_score16 (bfd_vma pc, struct disassemble_info *info, long given) case '\'': c++; - if ((given & (1 << bitstart)) != 0) + if ((given & (1u << bitstart)) != 0) func (stream, "%c", *c); break; default: |