aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-05-07 17:10:53 +0930
committerAlan Modra <amodra@gmail.com>2022-05-07 17:32:25 +0930
commit69464d2267c47e91f9ba77726c745d82b8864c88 (patch)
treed29006051fce81a4d5d5d959bbe831da289ed997
parent5a91f93b983184c64b3a9332f5f4339d17941d76 (diff)
downloadgdb-69464d2267c47e91f9ba77726c745d82b8864c88.zip
gdb-69464d2267c47e91f9ba77726c745d82b8864c88.tar.gz
gdb-69464d2267c47e91f9ba77726c745d82b8864c88.tar.bz2
Fix multiple ubsan warnings in i386-dis.c
Commit 39fb369834a3 "opcodes: Make i386-dis.c thread-safe" introduced a number of casts to bfd_signed_vma that cause undefined behaviour with a 32-bit libbfd. Revert those changes. * i386-dis.c (OP_E_memory): Do not cast disp to bfd_signed_vma for negation. (get32, get32s): Don't use bfd_signed_vma here.
-rw-r--r--opcodes/i386-dis.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index 1e32663..6ef091e 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -11634,7 +11634,7 @@ OP_E_memory (instr_info *ins, int bytemode, int sizeflag)
{
*ins->obufp++ = '-';
*ins->obufp = '\0';
- disp = - (bfd_signed_vma) disp;
+ disp = -disp;
}
if (havedisp)
@@ -11739,7 +11739,7 @@ OP_E_memory (instr_info *ins, int bytemode, int sizeflag)
{
*ins->obufp++ = '-';
*ins->obufp = '\0';
- disp = - (bfd_signed_vma) disp;
+ disp = -disp;
}
print_displacement (ins, ins->scratchbuf, disp);
@@ -11905,28 +11905,28 @@ get64 (instr_info *ins ATTRIBUTE_UNUSED)
static bfd_signed_vma
get32 (instr_info *ins)
{
- bfd_signed_vma x = 0;
+ bfd_vma x = 0;
FETCH_DATA (ins->info, ins->codep + 4);
- x = *ins->codep++ & (bfd_signed_vma) 0xff;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 8;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 16;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 24;
+ x = *ins->codep++ & (bfd_vma) 0xff;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 8;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 16;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 24;
return x;
}
static bfd_signed_vma
get32s (instr_info *ins)
{
- bfd_signed_vma x = 0;
+ bfd_vma x = 0;
FETCH_DATA (ins->info, ins->codep + 4);
- x = *ins->codep++ & (bfd_signed_vma) 0xff;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 8;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 16;
- x |= (*ins->codep++ & (bfd_signed_vma) 0xff) << 24;
+ x = *ins->codep++ & (bfd_vma) 0xff;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 8;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 16;
+ x |= (*ins->codep++ & (bfd_vma) 0xff) << 24;
- x = (x ^ ((bfd_signed_vma) 1 << 31)) - ((bfd_signed_vma) 1 << 31);
+ x = (x ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31);
return x;
}