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.
This commit is contained in:
Ori Bernstein 2022-01-07 01:43:52 +00:00
parent bf322dfbf3
commit 70edb7fbae

View file

@ -377,19 +377,20 @@ objread(Req *r, Gitaux *aux)
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)
{