public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ubsan: undefined shift in sign_extend
@ 2022-08-13  6:50 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-08-13  6:50 UTC (permalink / raw)
  To: binutils

	* libhppa.h (sign_extend): Avoid undefined behaviour.

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;
 }

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-13  6:50 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:50 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).