From patchwork Sat Jul 27 11:49:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1965639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ecpzjMwH; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WWNGV3f1Zz1ybY for ; Sat, 27 Jul 2024 21:50:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7759C384AB76 for ; Sat, 27 Jul 2024 11:50:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C22AE384AB63 for ; Sat, 27 Jul 2024 11:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C22AE384AB63 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C22AE384AB63 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722080983; cv=none; b=ngIWZ5MwH8cVbLCkg1mo0JXQdFl5+uuAVRTdHJmHW/9fOVUIKv7mgjq3bH9g29nNE6uDFK9hvS+aeTo5Xyhgd1x4RwCyfFbFpax+NS2BFJllJdpD9yUo3xccP7p5TQ7IKovElEz2q2qDHWEIM1X9abBkC0wYLBaib946z10CcXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722080983; c=relaxed/simple; bh=+MsFsH06XmUiT8ou7HuyKKcrSfnMqFaFPFtvpyV7M9Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=niI9yEOeETmODTMtGTHxp1zAn2/rkLB5tX5m4mie8eh6Z/ILAPdUHcJanfw1mWN4Rm+rdVsQm/yVBYE8aWNv477b2JNbAjt65RHeZtWromKIM6BzeGPLZ+n7F89J+Ga3K/8gpdRP+XvQMSMFD9+gcWwPTAwfVwNfvpm5dNsBSek= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722080981; 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=nteNK8xuvzPQfiNKxs6w4MRJwgFU3Bsg4cTLdSsJLvk=; b=ecpzjMwH9pUFQBp89CamGei+rgfIPXxn0Ky/zoQeAteqzKcftWBxpEAxfYDuPFqiNZ7vYc Y9QLLVu6nGgc5s6JGXggR/ykK2cR2lEtcjdfOcpvs0NjZ2OG2+pTWj1me7QYoKMPbBgb1C 4v5q8jYa/ZzJ8r2hkb/6tUPMXZN8tkA= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-jEsduZxqO76bIkFddJZzaA-1; Sat, 27 Jul 2024 07:49:39 -0400 X-MC-Unique: jEsduZxqO76bIkFddJZzaA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D94D319560AD; Sat, 27 Jul 2024 11:49:37 +0000 (UTC) Received: from localhost (unknown [10.42.28.14]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1533E300018D; Sat, 27 Jul 2024 11:49:36 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix -Wsign-compare warning in Date: Sat, 27 Jul 2024 12:49:24 +0100 Message-ID: <20240727114935.460444-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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_H4, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- Cast ptrdiff_t to size_t to avoid a -Wsign-compare warning. We can check in __to_chars_i that the ptrdiff_t won't be negative, so that we know the cast is safe. libstdc++-v3/ChangeLog: * include/std/charconv (__to_chars_16, __to_chars_10) (__to_chars_8, __to_chars_2, __to_chars): Cast ptrdiff_t to size_t for comparison. (__to_chars_i): Check for first >= last instead of first == last for initial sanity check. --- libstdc++-v3/include/std/charconv | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index e516e3b2da8..00c4f206922 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -126,7 +126,7 @@ namespace __detail const unsigned __len = __to_chars_len(__val, __base); - if (__builtin_expect((__last - __first) < __len, 0)) + if (__builtin_expect(size_t(__last - __first) < __len, 0)) { __res.ptr = __last; __res.ec = errc::value_too_large; @@ -166,7 +166,7 @@ namespace __detail const unsigned __len = (__to_chars_len_2(__val) + 3) / 4; - if (__builtin_expect((__last - __first) < __len, 0)) + if (__builtin_expect(size_t(__last - __first) < __len, 0)) { __res.ptr = __last; __res.ec = errc::value_too_large; @@ -212,7 +212,7 @@ namespace __detail const unsigned __len = __to_chars_len(__val, 10); - if (__builtin_expect((__last - __first) < __len, 0)) + if (__builtin_expect(size_t(__last - __first) < __len, 0)) { __res.ptr = __last; __res.ec = errc::value_too_large; @@ -246,7 +246,7 @@ namespace __detail else __len = (__to_chars_len_2(__val) + 2) / 3; - if (__builtin_expect((__last - __first) < __len, 0)) + if (__builtin_expect(size_t(__last - __first) < __len, 0)) { __res.ptr = __last; __res.ec = errc::value_too_large; @@ -288,7 +288,7 @@ namespace __detail const unsigned __len = __to_chars_len_2(__val); - if (__builtin_expect((__last - __first) < __len, 0)) + if (__builtin_expect(size_t(__last - __first) < __len, 0)) { __res.ptr = __last; __res.ec = errc::value_too_large; @@ -323,7 +323,7 @@ namespace __detail using _Up = __detail::__unsigned_least_t<_Tp>; _Up __unsigned_val = __value; - if (__first == __last) [[__unlikely__]] + if (__first >= __last) [[__unlikely__]] return { __last, errc::value_too_large }; if (__value == 0)