ref: 33bdd7e6c2bbfc7e2373b4e8d0371fd89dc31e52
parent: 6d3daa4092f891a5e9a1762177f75c75a6d5adf9
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)
--
⑨