Skip to contentSkip to conversation

fix for 'negative position' error

PATCH In review Ruth Alkema 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix for 'negative position' error

Quoted 1 line

From 78972d51ddd6bcbdf25bd49d2a033c005cf301b1

From: Ruth Alkema <[email protected]>
Date: Wed, 11 Mar 2009 15:49:22 +0100

---
 .../src/org/spearce/jgit/lib/WindowCache.java      |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java +1 -1
index 4b7e10d..5340da9 100644
@@ -253,7 +253,7 @@ private static synchronized final void getImpl(final WindowCursor curs,
 		releaseMemory();
 		runClearedWindowQueue();
 
-		wp.allocWindow(curs, id, id << windowSizeShift, wsz);
+		wp.allocWindow(curs, id, ((long) id) << windowSizeShift, wsz);
 		final ByteWindow<?> e = curs.window;
 		e.chainNext = cache[idx];
 		cache[idx] = e;
Signature · 1 line
1.6.0.6
#1 lore raw

org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java private static synchronized final void getImpl(final WindowCursor curs, · line 256

Quoted 10 lines · Ruth Alkema
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java +1 -1
index 4b7e10d..5340da9 100644
@@ -253,7 +253,7 @@ private static synchronized final void getImpl(final WindowCursor curs,
 		releaseMemory();
 		runClearedWindowQueue();
 
-		wp.allocWindow(curs, id, id << windowSizeShift, wsz);
+		wp.allocWindow(curs, id, ((long) id) << windowSizeShift, wsz);

Ouch.

Thanks for the fix!

Signature · 1 line
Shawn.
#2 lore raw

On second thought, I think that my previous patch can still go wrong for large values in 'position' I think the following patch should work.

Kind regards, I hope the email is according to the guidelines for submitting patches, I am new to git, I used 'amend previous commit', I am not sure if that is correct in this case.

Ruth Alkema

Quoted 1 line

From 5e7200f02f91d948278fb515be59bfe2db535b66 Mon Sep 17 00:00:00 2001

From: Ruth Alkema <[email protected]>
Date: Wed, 11 Mar 2009 16:42:45 +0100
Subject: [PATCH] fix for 'negative position' error

---
 .../src/org/spearce/jgit/lib/WindowCache.java      |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java +1 -1
index 4b7e10d..597ad61 100644
@@ -253,7 +253,7 @@ private static synchronized final void getImpl(final WindowCursor curs,
 		releaseMemory();
 		runClearedWindowQueue();
 
-		wp.allocWindow(curs, id, id << windowSizeShift, wsz);
+		wp.allocWindow(curs, id, (position >> windowSizeShift) << windowSizeShift, wsz);
 		final ByteWindow<?> e = curs.window;
 		e.chainNext = cache[idx];
 		cache[idx] = e;
Signature · 1 line
1.6.0.6
Quoted 16 lines · Shawn O. Pearce

org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java private static synchronized final void getImpl(final WindowCursor curs, · line 256

Quoted 10 lines · Ruth Alkema
org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java +1 -1
index 4b7e10d..5340da9 100644
@@ -253,7 +253,7 @@ private static synchronized final void getImpl(final WindowCursor curs,
 		releaseMemory();
 		runClearedWindowQueue();
 
-		wp.allocWindow(curs, id, id << windowSizeShift, wsz);
+		wp.allocWindow(curs, id, ((long) id) << windowSizeShift, wsz);

Ouch.

Thanks for the fix!