# [PATCH] Fix a comparison bug in diff-delta.c

3 messages from 2006-08-23 to 2006-08-23. Participants: Pierre Habouzit, Johannes Schindelin.
Thread: https://gitlist.dev/t/5362

## Pierre Habouzit, 2006-08-23 09:17

Subject: [PATCH] Fix a comparison bug in diff-delta.c
Message-ID: <1156324675415-git-send-email-madcoder@debian.org>
URL: https://gitlist.dev/e/1156324675415-git-send-email-madcoder%40debian.org

```
  (1 << i) < hspace is compared in the `int` space rather that in the
  unsigned one.  the result will be wrong if hspace is between 0x40000000
  and 0x80000000.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---

  This is a replacement for <1156300368160-git-send-email-madcoder@debian.org>
  avoiding the ugly cast, and using 1u instead.

 diff-delta.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/diff-delta.c b/diff-delta.c
index 7da9205..51e2e56 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -152,7 +152,7 @@ struct delta_index * create_delta_index(
 	   initialization in create_delta(). */
 	entries = (bufsize - 1)  / RABIN_WINDOW;
 	hsize = entries / 4;
-	for (i = 4; (1 << i) < hsize && i < 31; i++);
+	for (i = 4; (1u << i) < hsize && i < 31; i++);
 	hsize = 1 << i;
 	hmask = hsize - 1;
 
-- 
1.4.1.1

```

## Johannes Schindelin, 2006-08-23 13:45

Subject: Re: [PATCH] Fix a comparison bug in diff-delta.c
Message-ID: <Pine.LNX.4.63.0608231542380.28360@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0608231542380.28360%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <1156324675415-git-send-email-madcoder@debian.org>

```
Hi,

On Wed, 23 Aug 2006, Pierre Habouzit wrote:

> -	for (i = 4; (1 << i) < hsize && i < 31; i++);
> +	for (i = 4; (1u << i) < hsize && i < 31; i++);

The variable i never takes on the value 31 (or any higher value), so there 
is no bug here. Unless you port git to a system where an int has less than 
32 bit.

Ciao,
Dscho

```

## Pierre Habouzit, 2006-08-23 14:31

Subject: Re: [PATCH] Fix a comparison bug in diff-delta.c
Message-ID: <200608231631.12958.madcoder@debian.org>
URL: https://gitlist.dev/e/200608231631.12958.madcoder%40debian.org
In-Reply-To: <Pine.LNX.4.63.0608231542380.28360@wbgn013.biozentrum.uni-wuerzburg.de>

```
Le mer 23 août 2006 15:45, Johannes Schindelin a écrit :
> Hi,
>
> On Wed, 23 Aug 2006, Pierre Habouzit wrote:
> > -	for (i = 4; (1 << i) < hsize && i < 31; i++);
> > +	for (i = 4; (1u << i) < hsize && i < 31; i++);
>
> The variable i never takes on the value 31 (or any higher value), so
> there is no bug here. Unless you port git to a system where an int
> has less than 32 bit.

that remains quite tasteless though, and maybe that patch can be 
integrated to the "cleanup" series I sent later today.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

```
