public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: ubsan: undefined shift in sign_extend
Date: Sat, 13 Aug 2022 16:20:34 +0930	[thread overview]
Message-ID: <YvdJurMkIO9jaiiv@squeak.grove.modra.org> (raw)

	* 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

                 reply	other threads:[~2022-08-13  6:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YvdJurMkIO9jaiiv@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).