From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix _Hash_bytes for I16LP32 targets [PR107885]
Date: Mon, 28 Nov 2022 17:00:05 +0000 [thread overview]
Message-ID: <20221128170005.61262-1-jwakely@redhat.com> (raw)
Tested x86_64-linux, built on msp430-elf and h8300-elf. Pushed to trunk.
-- >8 --
For H8/300 size_t is 32 bits wide, but (unsigned char)buf[2] << 16
promotes to int which is only 16 bits wide. The shift is then undefined.
This fixes it by converting to size_t before shifting.
libstdc++-v3/ChangeLog:
PR libstdc++/107885
* libsupc++/hash_bytes.cc (_Hash_bytes): Convert to size_t
instead of implicit integer promotion to 16 bits.
---
libstdc++-v3/libsupc++/hash_bytes.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libstdc++-v3/libsupc++/hash_bytes.cc b/libstdc++-v3/libsupc++/hash_bytes.cc
index ffdd04f7602..67e2dbb1a0f 100644
--- a/libstdc++-v3/libsupc++/hash_bytes.cc
+++ b/libstdc++-v3/libsupc++/hash_bytes.cc
@@ -90,17 +90,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
len -= 4;
}
+ size_t k;
// Handle the last few bytes of the input array.
switch(len)
{
case 3:
- hash ^= static_cast<unsigned char>(buf[2]) << 16;
+ k = static_cast<unsigned char>(buf[2]);
+ hash ^= k << 16;
[[gnu::fallthrough]];
case 2:
- hash ^= static_cast<unsigned char>(buf[1]) << 8;
+ k = static_cast<unsigned char>(buf[1]);
+ hash ^= k << 8;
[[gnu::fallthrough]];
case 1:
- hash ^= static_cast<unsigned char>(buf[0]);
+ k = static_cast<unsigned char>(buf[0]);
+ hash ^= k;
hash *= m;
};
--
2.38.1
reply other threads:[~2022-11-28 17:00 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=20221128170005.61262-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.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).