Re: [PATCH] @{-<n>}: avoid crash with corrupt reflog
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 19, 2009, 14:57 UTC
- Message-ID
- <alpine.DEB.1.00.0901191547220.3586@pacific.mpi-cbg.de>
- In-Reply-To
- <alpine.DEB.1.00.0901191338470.3586@pacific.mpi-cbg.de>
Hi,
On Mon, 19 Jan 2009, Johannes Schindelin wrote:
Show 24 quoted lines
> diff --git a/sha1_name.c b/sha1_name.c
> index 9e5f444..853bac6 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -705,18 +705,18 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
> size_t len;
> int nth;
>
> - if (!prefixcmp(message, "checkout: moving from ")) {
> - match = message + strlen("checkout: moving from ");
> - if ((target = strstr(match, " to ")) != NULL)
> - target += 4;
> - }
> -
> - if (!match)
> + if (prefixcmp(message, "checkout: moving from "))
> return 0;
>
> - len = target - match - 4;
> - if (target[len] == '\n' && !strncmp(match, target, len))
> - return 0;
> + match = message + strlen("checkout: moving from ");
> + if ((target = strstr(match, " to ")) != NULL) {
> + len = target - match - 4;Aargh, the "- 4" is wrong, of course.
Show 9 quoted lines
> + target += 4; > + if (target[len] == '\n' && !strncmp(match, target, len)) > + return 0; > + } > + else > + len = strchrnul(match, ' ') - match; > > nth = cb->cnt++ % cb->alloc; > strbuf_reset(&cb->buf[nth]);
Sorry for the noise, Dscho