# [PATCH] archive.c: format_subst - fixed bogus argument to memchr

3 messages from 2008-04-23 to 2008-04-23. Participants: Ariel Badichi, René Scharfe.
Thread: https://gitlist.dev/t/13224

## Ariel Badichi, 2008-04-23 00:24

Subject: [PATCH] archive.c: format_subst - fixed bogus argument to memchr
Message-ID: <87od81peog.fsf@sneeze.site>
URL: https://gitlist.dev/e/87od81peog.fsf%40sneeze.site

```

Also removed a superfluous test.

Signed-off-by: Ariel Badichi <abadichi@bezeqint.net>
---
 archive.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/archive.c b/archive.c
index fb159fe..7a32c19 100644
--- a/archive.c
+++ b/archive.c
@@ -16,9 +16,9 @@ static void format_subst(const struct commit *commit,
 		const char *b, *c;
 
 		b = memmem(src, len, "$Format:", 8);
-		if (!b || src + len < b + 9)
+		if (!b)
 			break;
-		c = memchr(b + 8, '$', len - 8);
+		c = memchr(b + 8, '$', (src + len) - b - 8);
 		if (!c)
 			break;
 
-- 
1.5.5.1.57.g5909c

```

## Ariel Badichi, 2008-04-23 01:28

Subject: Re: [PATCH] archive.c: format_subst - fixed bogus argument to memchr
Message-ID: <87y775nyvf.fsf@sneeze.site>
URL: https://gitlist.dev/e/87y775nyvf.fsf%40sneeze.site
In-Reply-To: <87od81peog.fsf@sneeze.site>

```
Ariel Badichi <abadichi@bezeqint.net> writes:

Arf.  Sorry about the duplicates.

Ariel

```

## René Scharfe, 2008-04-23 15:54

Subject: Re: [PATCH] archive.c: format_subst - fixed bogus argument to memchr
Message-ID: <480F5BBD.8090101@lsrfire.ath.cx>
URL: https://gitlist.dev/e/480F5BBD.8090101%40lsrfire.ath.cx
In-Reply-To: <87od81peog.fsf@sneeze.site>

```
Ariel Badichi schrieb:
> Also removed a superfluous test.
> 
> Signed-off-by: Ariel Badichi <abadichi@bezeqint.net>
> ---
>  archive.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/archive.c b/archive.c
> index fb159fe..7a32c19 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -16,9 +16,9 @@ static void format_subst(const struct commit *commit,
>  		const char *b, *c;
>  
>  		b = memmem(src, len, "$Format:", 8);
> -		if (!b || src + len < b + 9)
> +		if (!b)
>  			break;

OK.

> -		c = memchr(b + 8, '$', len - 8);
> +		c = memchr(b + 8, '$', (src + len) - b - 8);
>  		if (!c)
>  			break;

Ouch.  Perhaps rearranging it to "len - (b - src) - 8" would make it a
little easier to read?  Anyway, thanks and:

Acked-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>

```
