From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 7D1FD1F4D7 for ; Wed, 25 May 2022 18:27:45 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="bK3Idn4e"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343650AbiEYS1m (ORCPT ); Wed, 25 May 2022 14:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231913AbiEYS1l (ORCPT ); Wed, 25 May 2022 14:27:41 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E018AAE26A for ; Wed, 25 May 2022 11:27:39 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id D59A212F248; Wed, 25 May 2022 14:27:38 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=7KK0dDbXx11/ XiLMk+Md0wE/n7dxnPs0vx7ffG/FORE=; b=bK3Idn4eLnTCrLsy1AHCKTPPqDDC 8UdKV0EetBClv9w97Sm0THQgD0d2u8x7EveudwQrkow3/Wu/UwkRNTmxg7xLRlP+ yO7EJMvb8OQwtcmBm+UStJyuvoGg1cgBavtf0zwjPTkSCr6wm+pGqxiDt3eInw5B Zus6jHXoz92JxLY= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CC39812F247; Wed, 25 May 2022 14:27:38 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.83.92.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 3255A12F245; Wed, 25 May 2022 14:27:38 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Derrick Stolee Cc: Johannes Schindelin , =?utf-8?B?w4Z2YXIg?= =?utf-8?B?QXJuZmrDtnLDsA==?= Bjarmason , Johannes Schindelin via GitGitGadget , git@vger.kernel.org Subject: Re: [PATCH 4/4] dir.c: avoid "exceeds maximum object size" error with GCC v12.x References: <365889ee96e37dc9dcbe60d98880eb256dae90ee.1653351786.git.gitgitgadget@gmail.com> <220524.86k0abxyqa.gmgdl@evledraar.gmail.com> Date: Wed, 25 May 2022 11:27:37 -0700 In-Reply-To: (Derrick Stolee's message of "Wed, 25 May 2022 09:39:53 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Pobox-Relay-ID: 5AEB1748-DC58-11EC-89F4-CB998F0A682E-77302942!pb-smtp2.pobox.com Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Derrick Stolee writes: > On 5/24/2022 5:05 PM, Johannes Schindelin wrote:> On Tue, 24 May 2022, = =C3=86var Arnfj=C3=B6r=C3=B0 Bjarmason wrote: >>> On Tue, May 24 2022, Johannes Schindelin via GitGitGadget wrote: >>>> + /* >>>> + * It should not be possible to overflow `ptrdiff_t` by passing in= an >>>> + * insanely long URL, but GCC does not know that and will complain >>>> + * without this check. >>>> + */ >>>> + if (end - start < 0) >>>> + die(_("No directory name could be guessed.\n" >>> >>> This should start with a lower-case letter, see CodingGuidelines. >>=20 >> This message is copied from existing code later in the same function. >> Since it is a translateable message, I do not want to edit it because = that >> would cause unnecessary work of the translators. Especially given that= we >> do not even expect this message to be shown, ever, but we only add thi= s >> hunk for GCC's benefit. > > Perhaps this should be a BUG() statement, then? Without any > translation? Yeah, both are good. If somehow the caller managed to pass such a long URL then it can be considered a data error at runtime, and not that the user detected a bug in our code, so in that sense die() would be appropriate. It is like xmalloc() running out of memory. On the other hand, the "should not be possible to overflow" in the comment implicitly assumes that it is impossible to pass insanely long URL to trigger the condition from places we think of offhand, like the command line, where the input is limited to a much shorter string. As "we detected a situation that should not happen unless there is a programming or design bug" is what BUG() means, it is also good here---our assumption that this should not be possible turned out to be faulty, so we noticed a design bug. I wonder if we can add a separate macro to add more to the documentation value, though. With something like #define FALSE_WARNING(expression, message) \ do { if (expression) { BUG(message); } while (0) the above would just become FALSE_WARNING(end - start < 0, "ptrdiff_t would not overflow here"); without a need for a big comment before it. We might even be able to optimize it out when building with compilers that do not need the workaround.