shithub: git9

Download patch

ref: 8c6caa849400ae408140cbe04eb02f299dd82e82
parent: 559e589947b8e3da2222fe21f369774bb0a92ce7
author: Ori Bernstein <[email protected]>
date: Mon Dec 30 15:24:42 EST 2019

fix operator precedence

--- a/pack.c
+++ b/pack.c
@@ -310,9 +310,7 @@
 	er = dst->data + nr;
 	r = dst->data;
 
-	while(1){
-		if(d == ed)
-			break;
+	while(d != ed){
 		c = *d++;
 		if(!c){
 			werrstr("bad delta encoding");
@@ -323,15 +321,15 @@
 			o = 0;
 			l = 0;
 			/* Offset in base */
-			if(d != ed && c & 0x01) o |= (*d++ <<  0) & 0x000000ff;
-			if(d != ed && c & 0x02) o |= (*d++ <<  8) & 0x0000ff00;
-			if(d != ed && c & 0x04) o |= (*d++ << 16) & 0x00ff0000;
-			if(d != ed && c & 0x08) o |= (*d++ << 24) & 0xff000000;
+			if(d != ed && (c & 0x01)) o |= (*d++ <<  0) & 0x000000ff;
+			if(d != ed && (c & 0x02)) o |= (*d++ <<  8) & 0x0000ff00;
+			if(d != ed && (c & 0x04)) o |= (*d++ << 16) & 0x00ff0000;
+			if(d != ed && (c & 0x08)) o |= (*d++ << 24) & 0xff000000;
 
 			/* Length to copy */
-			if(d != ed && c & 0x10) l |= (*d++ <<  0) & 0x0000ff;
-			if(d != ed && c & 0x20) l |= (*d++ <<  8) & 0x00ff00;
-			if(d != ed && c & 0x40) l |= (*d++ << 16) & 0xff0000;
+			if(d != ed && (c & 0x10)) l |= (*d++ <<  0) & 0x0000ff;
+			if(d != ed && (c & 0x20)) l |= (*d++ <<  8) & 0x00ff00;
+			if(d != ed && (c & 0x40)) l |= (*d++ << 16) & 0xff0000;
 			if(l == 0) l = 0x10000;
 
 			assert(o + l <= base->size);
@@ -339,12 +337,11 @@
 			r += l;
 		/* inline data */
 		}else{
-			assert(c < ed - d);
+			assert(c <= ed - d);
 			memmove(r, d, c);
 			d += c;
 			r += c;
 		}
-
 	}
 	if(r != er){
 		werrstr("truncated delta");