From 70edb7fbae4f0a38593c0dc1f936838adc6861ac Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Fri, 7 Jan 2022 01:43:52 +0000 Subject: 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. --- sys/src/cmd/git/fs.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sys/src/cmd/git') 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) { -- cgit v1.2.3