From: Michael Haggerty Date: Mon, 15 Jan 2018 12:17:34 GMT Subject: [PATCH 2/3] create_snapshot(): exit early if the file was empty Message-ID: <02915e24958741927467ed750e9782d02ec40c80.1516017331.git.mhagger@alum.mit.edu> In-Reply-To: <20180114191416.2368-1-kgybels@infogroep.be> If the `packed_refs` files is entirely empty (i.e., not even a header line), then `load_contents()` returns 1 even though `snapshot->buf` and `snapshot->eof` both end up set to NULL. In that case, the subsequent processing that `create_snapshot()` does is unnecessary, and also involves computing `NULL - NULL` and `NULL + 0`, which are probably safe in real life but are technically undefined in C. Sidestep both issues by exiting early if `snapshot->buf` is NULL. Signed-off-by: Michael Haggerty --- refs/packed-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index f20f05b4df..36796d65f0 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -613,7 +613,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs) acquire_snapshot(snapshot); snapshot->peeled = PEELED_NONE; - if (!load_contents(snapshot)) + if (!load_contents(snapshot) || !snapshot->buf) return snapshot; /* If the file has a header line, process it: */ -- 2.14.2