shithub: git9

Download patch

ref: 542d69a45a4d26ba99280ede5e77d5ecff97db1f
parent: dee2d0ad28cfe6ec789c7597f678c54168918bad
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 31 19:43:06 EST 2021

git/log: correct heap indexing.

fencepost errors suck, and translating 1-indexing
pseudocode to 0-indexed real code is a pain.

--- a/log.c
+++ b/log.c
@@ -198,13 +198,13 @@
 		heap = earealloc(heap, heapsz, sizeof(Object*));
 	}
 	heap[nheap++] = o;
-	for(i = nheap - 1; i > 0; i /= 2){
+	for(i = nheap - 1; i > 0; i = (i-1)/2){
 		o = heap[i];
 		p = heap[(i-1)/2];
 		if(o->commit->mtime < p->commit->mtime)
 			break;
 		heap[i] = p;
-		heap[i/2] = o;
+		heap[(i-1)/2] = o;
 	}
 }