summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2022-01-07 01:43:52 +0000
committerOri Bernstein <ori@eigenstate.org>2022-01-07 01:43:52 +0000
commit70edb7fbae4f0a38593c0dc1f936838adc6861ac (patch)
tree6955f892cbeb34a0a0e12f410af1c1586ef9421a /sys/src
parentbf322dfbf37c5b1ea392e6f36775a06cde96a942 (diff)
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.
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/cmd/git/fs.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/src/cmd/git/fs.c b/sys/src/cmd/git/fs.c
index 6bed5521f..b9710f324 100644
--- a/sys/src/cmd/git/fs.c
+++ b/sys/src/cmd/git/fs.c
@@ -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)
{