From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id E8EA538518AD; Mon, 28 Nov 2022 16:57:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8EA538518AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669654663; bh=Lr6XdTBmD9u2spa5qil2xDXyMCHvkvdQ0LfsuDtlR/0=; h=From:To:Subject:Date:From; b=TlTeXTAz9bg/TedtKotts5AkKrQuDnkkankwcPejxbKVlLp9re2uFZ9KXoQ/HIC7B ek6WMVu0FnlsytgbkQj8/RRgvWvXI4YAgy0+6IIvyJoxmhVv8Vj7TzXM2KCCwDu7hK /yagMYbZ5+Vwu7w55rEuTXrrVvCQXRYFcraNhQo4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4369] libstdc++: Fix _Hash_bytes for I16LP32 targets [PR107885] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: f7a41b5cfd7406da1f2e5a0f1f813521d3dc2bb2 X-Git-Newrev: 7b79fa930917da735f02b4f6911dfbb0a91f9714 Message-Id: <20221128165743.E8EA538518AD@sourceware.org> Date: Mon, 28 Nov 2022 16:57:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7b79fa930917da735f02b4f6911dfbb0a91f9714 commit r13-4369-g7b79fa930917da735f02b4f6911dfbb0a91f9714 Author: Jonathan Wakely Date: Mon Nov 28 10:52:23 2022 +0000 libstdc++: Fix _Hash_bytes for I16LP32 targets [PR107885] 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. Diff: --- 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(buf[2]) << 16; + k = static_cast(buf[2]); + hash ^= k << 16; [[gnu::fallthrough]]; case 2: - hash ^= static_cast(buf[1]) << 8; + k = static_cast(buf[1]); + hash ^= k << 8; [[gnu::fallthrough]]; case 1: - hash ^= static_cast(buf[0]); + k = static_cast(buf[0]); + hash ^= k; hash *= m; };