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.129.124]) by sourceware.org (Postfix) with ESMTP id CE1D63858D26 for ; Fri, 26 Jul 2024 17:11:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE1D63858D26 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 CE1D63858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722013885; cv=none; b=u+uTekFivJea9aBILTab8EZnVfEj+8OrAH1iFbxq8q4GqnCe7azUakIqGDhGCCQuYQp2EU5A24+ikXPg/rzSh8KIyeN1ehIYPW27FdUdDrLPnBjAvmhUhziHxbW1P5tDGnLr4gUv/dS81wWCnuCWOQL+utQIJOHxQhz/VAuq/Ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722013885; c=relaxed/simple; bh=J8ycS88oCJjvqHbaphK6sL+c+6aKQyDLOrodQIfxvRM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=avCnbBjwCR7nRuZG4hGqgT8YqpxRcuATORrWEdItaquX/agbp9JX42vFCurJe3D3YgJYHPb/mzn5IcwANNgYHnT6xW5CgYV1R1T00E1nOyVIvyEBfKigSX/qX4/IQNRwYcPyso5/HCUtU571HETB/l836V9/N7nLZXU9ZFlvzbo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722013882; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=pPEBeA7OLFMcYLZVS/97RrDNU8opwrQQ62RQCSaIyt0=; b=WNuaw6k2wL2g+rkmBTYxiXXyh1N2abaUJkUpw2EbXYZYCKm1ILUQQEC7oLF0uvRfvJ/RjQ VZe4SsmYygWYdTX2pBwr1iPQmHsZeCE+P3Hnzb/eZMZsYvC2SaZFuRHAPdcSmOgIR4e3ss i8e8vGbDbrnFgz4aBY66pRmHJeM71KE= Received: from mx-prod-mc-02.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-261-JRHkQm41OAa5dXSzd24AGQ-1; Fri, 26 Jul 2024 13:11:20 -0400 X-MC-Unique: JRHkQm41OAa5dXSzd24AGQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0CA981955D4C; Fri, 26 Jul 2024 17:11:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 510E81955F40; Fri, 26 Jul 2024 17:11:18 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 46QHBFkx2171019 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 26 Jul 2024 19:11:15 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 46QHBEiZ2171018; Fri, 26 Jul 2024 19:11:14 +0200 Date: Fri, 26 Jul 2024 19:11:14 +0200 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] gimple-ssa-sprintf: Fix typo in range check Message-ID: Reply-To: Jakub Jelinek References: <20240725234838.3804003-1-siddhesh@gotplt.org> MIME-Version: 1.0 In-Reply-To: <20240725234838.3804003-1-siddhesh@gotplt.org> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,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 List-Id: On Thu, Jul 25, 2024 at 07:48:38PM -0400, Siddhesh Poyarekar wrote: > The code to scale ranges for wide chars in format_string incorrectly > checks range.likely to scale range.unlikely, which is a copy-paste typo > from the immediate previous condition. > > gcc/ChangeLog: > > gimple-ssa-sprintf.cc (format_string): Fix type in range check > for UNLIKELY for wide chars. > > Signed-off-by: Siddhesh Poyarekar LGTM. What exactly the code really wants to do is unclear to me, what does the INT_MAX on the target have to do with the minimum/maximum/expected sizes of %S or %ls printed strings is unclear, target PTRDIFF_MAX maybe. And why it uses this if (slen.range.something < target_int_max ()) slen.range.something *= something_else; rather than say slen.range.something = MIN (slang.range.something * something_else, target_int_max ()); perhaps with some overflow checking is also something that is hard to guess. In any case, I think your patch is a step in the right direction. > --- a/gcc/gimple-ssa-sprintf.cc > +++ b/gcc/gimple-ssa-sprintf.cc > @@ -2623,7 +2623,7 @@ format_string (const directive &dir, tree arg, pointer_query &ptr_qry) > if (slen.range.likely < target_int_max ()) > slen.range.likely *= 2; > > - if (slen.range.likely < target_int_max ()) > + if (slen.range.unlikely < target_int_max ()) > slen.range.unlikely *= target_mb_len_max (); > > /* A non-empty wide character conversion may fail. */ > -- > 2.45.1 Jakub