Re: [PATCH 1/9] git_config_set: fix off-by-two
- From
Stefan Beller <sbeller@google.com>
- Date
- Mar 29, 2018, 18:15 UTC
- Message-ID
- <CAGZ79kapTWGsYznt7rr0QTNX+uH85TPY8AOA1jtDJ6_q8edX1Q@mail.gmail.com>
- In-Reply-To
- <899ea23951627426ccd0aac79f824af386c5590c.1522336130.git.johannes.schindelin@gmx.de>
On Thu, Mar 29, 2018 at 8:18 AM, Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
Show 20 quoted lines
> 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.
This commit message would be more convincing if we had it in test form.
[abc]a
is not written by Git, but would be written from an outside tool or person and we barely cope with it?
Thanks, Stefan
Show 23 quoted lines
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > --- > 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.16.2.windows.1.26.g2cc3565eb4b > >