* Fix multiple ubsan warnings in i386-dis.c
@ 2022-05-07 9:13 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-05-07 9:13 UTC (permalink / raw)
To: binutils
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.
diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index 1e3266329c1..6ef091ea7d7 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;
}
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-07 9:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07 9:13 Fix multiple ubsan warnings in i386-dis.c Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).