All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] create_delta_index: simplify condition always evaluating to true
@ 2013-08-15 19:37 Stefan Beller
  2013-08-15 21:21 ` Eric Sunshine
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Stefan Beller @ 2013-08-15 19:37 UTC (permalink / raw)
  To: git, gitster; +Cc: Stefan Beller

When checking the previous lines in that function, we can deduct that
hsize must always be smaller than (1u<<31), since 506049c7df2c6
(fix >4GiB source delta assertion failure), because the entries is
capped at an upper bound of 0xfffffffeU, so hsize contains a maximum
value of 0x3fffffff, which is smaller than (1u<<31), so i will never
be larger than 31.

Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 diff-delta.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/diff-delta.c b/diff-delta.c
index 93385e1..54da95b 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -154,8 +154,15 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
 		 */
 		entries = 0xfffffffeU / RABIN_WINDOW;
 	}
+
+	/*
+	 * Do not check i < 31 in the loop, because the assignement
+	 * previous to the loop makes sure, hsize is definitely
+	 * smaller than 1<<31, hence the loop will always stop
+	 * before i exceeds 31 resulting in an infinite loop.
+	 */
 	hsize = entries / 4;
-	for (i = 4; (1u << i) < hsize && i < 31; i++);
+	for (i = 4; (1u << i) < hsize; i++);
 	hsize = 1 << i;
 	hmask = hsize - 1;
 
-- 
1.8.4.rc3.498.g5af1768

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

end of thread, other threads:[~2013-08-17  7:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-15 19:37 [PATCH] create_delta_index: simplify condition always evaluating to true Stefan Beller
2013-08-15 21:21 ` Eric Sunshine
2013-08-15 21:34   ` Stefan Beller
2013-08-15 21:46     ` Eric Sunshine
2013-08-16  2:38       ` Nicolas Pitre
2013-08-16 16:47       ` Philip Oakley
2013-08-16 21:22         ` Stefan Beller
2013-08-17  6:58           ` Philip Oakley
2013-08-15 22:14     ` Philip Oakley
2013-08-15 21:43 ` Junio C Hamano
2013-08-15 22:04   ` Stefan Beller
2013-08-16  2:34   ` Nicolas Pitre
2013-08-16 11:43 ` brian m. carlson
2013-08-16 12:40   ` Eric Sunshine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.