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: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id B82F91F5AE for ; Thu, 10 Jun 2021 13:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbhFJNNN (ORCPT ); Thu, 10 Jun 2021 09:13:13 -0400 Received: from cloud.peff.net ([104.130.231.41]:51238 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230426AbhFJNNJ (ORCPT ); Thu, 10 Jun 2021 09:13:09 -0400 Received: (qmail 7666 invoked by uid 109); 10 Jun 2021 13:11:12 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 10 Jun 2021 13:11:12 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 29856 invoked by uid 111); 10 Jun 2021 13:11:12 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 10 Jun 2021 09:11:12 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 10 Jun 2021 09:11:11 -0400 From: Jeff King To: git@vger.kernel.org Cc: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Subject: Re: [PATCH] add_pending_object_with_path(): work around "gcc -O3" complaint Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Thu, Jun 10, 2021 at 09:06:44AM -0400, Jeff King wrote: > We can work around this by replacing our "did we hit the trailing NUL" > subscript dereference with a length check. We do not even have to pay > the cost for an extra strlen(), as we can pass our new length into > interpret_branch_name(), which was converting our "0" into a call to > strlen() anyway. > [...] > - if (0 < len && name[len] && buf.len) > + if (0 < len && len < namelen && buf.len) > strbuf_addstr(&buf, name + len); I guess another option would be to drop the check entirely. It is only protecting us from calling strbuf_addstr() with an empty string, which is a noop anyway (it would not even cause a useless allocation, since we know that buf is non-empty, and that it won't need to grow). I think I still prefer my original solution, though. -Peff