git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Pierre Habouzit <madcoder@debian.org>
Date
Aug 23, 2006, 02:32 UTC
Message-ID
<1156300368160-git-send-email-madcoder@debian.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>
---
  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
Next: Pierre Habouzit
Message 1 of 3 in “Fix a comparison bug in diff-delta.c”
  1. Fix a comparison bug in diff-delta.cPierre Habouzit, Aug 23, 2006
  2. Pierre HabouzitAug 23, 2006
  3. Nicolas PitreAug 23, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.