git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix a comparison bug in diff-delta.c
@ 2006-08-23  2:32 Pierre Habouzit
  2006-08-23  2:38 ` Pierre Habouzit
  2006-08-23  3:17 ` Nicolas Pitre
  0 siblings, 2 replies; 6+ messages in thread
From: Pierre Habouzit @ 2006-08-23  2:32 UTC (permalink / raw)
  To: git; +Cc: Pierre Habouzit

(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>
---

  I'm currently trying to make git compile with more strict gcc flags
(-g -O2 -Wall -Wextra -Wno-unused -Werror to be precise) and I've
spotted a first bug due to a signed/unsigned comparison.

  If I do understand that bit of code, it should not bite a lot of
people, but this is still a bug ;)


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

diff --git a/diff-delta.c b/diff-delta.c
index 7da9205..a1fadc9 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; (unsigned)(1 << i) < hsize && i < 31; i++);
 	hsize = 1 << i;
 	hmask = hsize - 1;
 
-- 
1.4.1.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] Fix a comparison bug in diff-delta.c
@ 2006-08-23  9:17 Pierre Habouzit
  2006-08-23 13:45 ` Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Habouzit @ 2006-08-23  9:17 UTC (permalink / raw)
  To: git; +Cc: Pierre Habouzit

  (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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-08-23 14:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-23  2:32 [PATCH] Fix a comparison bug in diff-delta.c Pierre Habouzit
2006-08-23  2:38 ` Pierre Habouzit
2006-08-23  3:17 ` Nicolas Pitre
  -- strict thread matches above, loose matches on Subject: below --
2006-08-23  9:17 Pierre Habouzit
2006-08-23 13:45 ` Johannes Schindelin
2006-08-23 14:31   ` Pierre Habouzit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).