From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.1 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id C2D7A1F424 for ; Mon, 9 Apr 2018 08:31:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751671AbeDIIbh (ORCPT ); Mon, 9 Apr 2018 04:31:37 -0400 Received: from mout.gmx.net ([212.227.15.18]:49207 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbeDIIbg (ORCPT ); Mon, 9 Apr 2018 04:31:36 -0400 Received: from [192.168.0.129] ([37.201.195.115]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MUpFU-1f00g505Yi-00Y8xj; Mon, 09 Apr 2018 10:31:25 +0200 Date: Mon, 9 Apr 2018 10:31:25 +0200 (DST) From: Johannes Schindelin X-X-Sender: virtualbox@MININT-6BKU6QN.europe.corp.microsoft.com To: git@vger.kernel.org cc: Junio C Hamano , Thomas Rast , Phil Haack , Jeff King , =?UTF-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0_Bjarmason?= , Stefan Beller , Jason Frey , Philip Oakley Subject: [PATCH v3 01/15] git_config_set: fix off-by-two In-Reply-To: Message-ID: <518729d5abdd93980f388821a96a69c8e4cde82e.1523262449.git.johannes.schindelin@gmx.de> References: User-Agent: Alpine 2.21.1 (DEB 209 2017-03-23) MIME-Version: 1.0 Content-Type: text/plain; charset=US-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+wkt37l0MRpdRWrcLqOJp8GN+htcPEnoz 82Vr6JZcxCsV6Rti5BXYOPh9edhYJcUtGqNa4VQVDbSGJaCENE= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently, we are slightly overzealous When removing an entry from a config file of this form: [abc]a [xyz] key = value When calling `git config --unset abc.a` on this file, it leaves this (invalid) config behind: [ [xyz] key = value The reason is that we try to search for the beginning of the line (or for the end of the preceding section header on the same line) that defines abc.a, but as an optimization, we subtract 2 from the offset pointing just after the definition before we call find_beginning_of_line(). That function, however, *also* performs that optimization and promptly fails to find the section header correctly. Signed-off-by: Johannes Schindelin --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index b0c20e6cb8a..5cc049aaef0 100644 --- a/config.c +++ b/config.c @@ -2632,7 +2632,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, } else copy_end = find_beginning_of_line( contents, contents_sz, - store.offset[i]-2, &new_line); + store.offset[i], &new_line); if (copy_end > 0 && contents[copy_end-1] != '\n') new_line = 1; -- 2.17.0.windows.1.4.g7e4058d72e3