From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS54825 147.75.192.0/21 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 247B81F406 for ; Tue, 12 Dec 2023 22:05:20 +0000 (UTC) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5658F1C20DD0 for ; Tue, 12 Dec 2023 22:05:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0401B64CDF; Tue, 12 Dec 2023 22:05:13 +0000 (UTC) Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C23B3 for ; Tue, 12 Dec 2023 14:05:07 -0800 (PST) Received: (qmail 19375 invoked by uid 109); 12 Dec 2023 22:05:06 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Tue, 12 Dec 2023 22:05:06 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 19953 invoked by uid 111); 12 Dec 2023 22:05:06 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 12 Dec 2023 17:05:06 -0500 Authentication-Results: peff.net; auth=none Date: Tue, 12 Dec 2023 17:05:05 -0500 From: Jeff King To: Junio C Hamano Cc: git@vger.kernel.org, Britton Kerin Subject: Re: [PATCH] revision: parse integer arguments to --max-count, --skip, etc., more carefully Message-ID: <20231212220505.GA1220605@coredump.intra.peff.net> References: <20231212013045.GE376323@coredump.intra.peff.net> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Tue, Dec 12, 2023 at 07:09:02AM -0800, Junio C Hamano wrote: > Jeff King writes: > > > This all looks pretty reasonable to me. > > > > I couldn't help but think, though, that surely we have some helpers for > > this already? But the closest seems to be git_parse_int(), which also > > allows unit factors. I'm not sure if allowing "-n 1k" would be a feature > > or a bug. ;) > > The change in question is meant to be a pure fix to replace a careless > use of atoi(). I do not mind to see a separate patch to add such a > feature later on top. Oh, I mostly meant that I would have turned to git_parse_int() as that already-existing helper, but it is not suitable because of the extra unit-handling. I think your patch draws the line in the right place. > > I wonder if there are more spots that could benefit. > > "git grep -e 'atoi('" would give somebody motivated a decent set of > #microproject ideas, but many hits are not suited for strtol_i(), > which is designed to parse an integer at the end of a string. Some > places use atoi() immediately followed by strspn() to skip over > digits, which means they are parsing an integer and want to continue > reading after the integer, which is incompatible with what > strtol_i() wants to do. They need either a separate helper or an > updated strtol_i() that optionally allows you to parse the prefix > and report where the integer ended, e.g., something like: Yeah, I agree this might be a good microproject (or leftoverbits) area, and the semantics for the helper you propose make sense to me. -Peff