public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] ubsan: undefined shift in sign_extend
Date: Sat, 13 Aug 2022 06:52:55 +0000 (GMT)	[thread overview]
Message-ID: <20220813065255.056EC3857C44@sourceware.org> (raw)

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


                 reply	other threads:[~2022-08-13  6:52 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=20220813065255.056EC3857C44@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@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).