From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D499F3858414 for ; Mon, 28 Nov 2022 17:00:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D499F3858414 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669654811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=B6uX56eJAOTsyy4R2Z99GaF7ULEv9fyeCj7eLutG6Z4=; b=SogfH1k3UlYGcDo64EixzVFic9sC8UP6wuyOYNpqWEAGrGIor8dV1gmK/jFmTeolcHBxkL ImvQXz68dQI3EbGMD/SrtO99BatfuUhqoa7i6sNSk/AzxUSXomEdz6vJcEDTAnU2VvTni9 TpvZW+d7QDiUEOZGmw7Tfio5z1qUovw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-3ps_McqNMtSEZ4k3g_8Y8A-1; Mon, 28 Nov 2022 12:00:09 -0500 X-MC-Unique: 3ps_McqNMtSEZ4k3g_8Y8A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A070780252E; Mon, 28 Nov 2022 17:00:09 +0000 (UTC) Received: from localhost (unknown [10.33.36.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68D78C15BA4; Mon, 28 Nov 2022 17:00:08 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20221128170005.61262-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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(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; }; -- 2.38.1