public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
From: gdb-buildbot@sergiodj.net
To: gdb-testers@sourceware.org
Subject: [binutils-gdb] ubsan: csky: left shift cannot be represented in type 'int'
Date: Wed, 11 Dec 2019 09:06:00 -0000	[thread overview]
Message-ID: <d93bba9e0d6c7bd3a570688612a3dd0a5eb0193a@gdb-build> (raw)

*** TEST RESULTS FOR COMMIT d93bba9e0d6c7bd3a570688612a3dd0a5eb0193a ***

commit d93bba9e0d6c7bd3a570688612a3dd0a5eb0193a
Author:     Alan Modra <amodra@gmail.com>
AuthorDate: Tue Dec 10 23:37:03 2019 +1030
Commit:     Alan Modra <amodra@gmail.com>
CommitDate: Wed Dec 11 11:38:45 2019 +1030

    ubsan: csky: left shift cannot be represented in type 'int'
    
    In the following buf is an unsigned char array, so elements are
    promoted to int before arithmetic operations.
    
      if (dis_info.info->endian == BFD_ENDIAN_BIG)
        while (n--)
          val |= buf[n] << (n*8);
      else
        for (i = 0; i < n; i++)
          val |= buf[i] << (i*8);
    
            * csky-dis.c (csky_chars_to_number): Rewrite.  Avoid signed
            overflow when collecting bytes of a number.

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 6b76f158c9..5cd7361512 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
+	* csky-dis.c (csky_chars_to_number): Rewrite.  Avoid signed
+	overflow when collecting bytes of a number.
+
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
 	* cris-dis.c (print_with_operands): Avoid signed integer
diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c
index ffdb596495..af830f3651 100644
--- a/opcodes/csky-dis.c
+++ b/opcodes/csky-dis.c
@@ -140,11 +140,11 @@ csky_chars_to_number (unsigned char * buf, int n)
   unsigned int val = 0;
 
   if (dis_info.info->endian == BFD_ENDIAN_BIG)
-    while (n--)
-      val |= buf[n] << (n*8);
-  else
     for (i = 0; i < n; i++)
-      val |= buf[i] << (i*8);
+      val = val << 8 | (buf[i] & 0xff);
+  else
+    for (i = n - 1; i >= 0; i--)
+      val = val << 8 | (buf[i] & 0xff);
   return val;
 }
 


             reply	other threads:[~2019-12-11  9:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11  9:06 gdb-buildbot [this message]
2019-12-11  9:01 ` Failures on Ubuntu-Aarch64-native-extended-gdbserver-m64, branch master gdb-buildbot
2019-12-11 15:41 ` Failures on Fedora-i686, " gdb-buildbot
2019-12-11 16:17 ` Failures on Fedora-x86_64-m64, " gdb-buildbot
2019-12-11 16:19 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2019-12-11 16:35 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2019-12-11 16:49 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot
2019-12-11 17:08 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot

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=d93bba9e0d6c7bd3a570688612a3dd0a5eb0193a@gdb-build \
    --to=gdb-buildbot@sergiodj.net \
    --cc=gdb-testers@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).