public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] ubsan: undefined shift in sign_extend
@ 2022-08-13 6:52 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-08-13 6:52 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9effb9f15f4811a80169801b5d2938961424a7d4
commit 9effb9f15f4811a80169801b5d2938961424a7d4
Author: Alan Modra <amodra@gmail.com>
Date: Sat Aug 13 14:07:31 2022 +0930
ubsan: undefined shift in sign_extend
* libhppa.h (sign_extend): Avoid undefined behaviour.
Diff:
---
bfd/libhppa.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bfd/libhppa.h b/bfd/libhppa.h
index 1de2d5c943b..ebaffe66abf 100644
--- a/bfd/libhppa.h
+++ b/bfd/libhppa.h
@@ -162,7 +162,7 @@ enum hppa_reloc_expr_type_alt
static inline unsigned ATTRIBUTE_UNUSED
sign_extend (unsigned x, unsigned len)
{
- unsigned signbit = (1 << (len - 1));
+ unsigned signbit = (1u << (len - 1));
unsigned mask = (signbit << 1) - 1;
return ((x & mask) ^ signbit) - signbit;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-13 6:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-13 6:52 [binutils-gdb] ubsan: undefined shift in sign_extend 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).