shithub: riscv

Download patch

ref: 70edb7fbae4f0a38593c0dc1f936838adc6861ac
parent: bf322dfbf37c5b1ea392e6f36775a06cde96a942
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 6 20:43:52 EST 2022

git/fs: remove trailing null bytes from parent file (thanks mcf)

due to the way the size of buf was calculated, the parent
file had one trailing null byte for each parent. also, while
we're here, replace the sprint with seprint, and compute the
size from how much we printed in.

--- a/sys/src/cmd/git/fs.c
+++ b/sys/src/cmd/git/fs.c
@@ -377,18 +377,19 @@
 static void
 readcommitparent(Req *r, Object *o)
 {
-	char *buf, *p;
+	char *buf, *p, *e;
 	int i, n;
 
-	n = o->commit->nparent * (40 + 2);
+	/* 40 bytes per hash, 1 per nl, 1 for terminator */
+	n = o->commit->nparent * (40 + 1) + 1;
 	buf = emalloc(n);
 	p = buf;
+	e = buf + n;
 	for (i = 0; i < o->commit->nparent; i++)
-		p += sprint(p, "%H\n", o->commit->parent[i]);
-	readbuf(r, buf, n);
+		p = seprint(p, e, "%H\n", o->commit->parent[i]);
+	readbuf(r, buf, p - buf);
 	free(buf);
 }
-
 
 static void
 gitattach(Req *r)