]> git.ipfire.org Git - thirdparty/git.git/commit
load_contents(): don't try to mmap an empty file
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 24 Jan 2018 11:14:15 +0000 (12:14 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Jan 2018 20:55:26 +0000 (12:55 -0800)
commit01caf20d57aea73e67337ba1d396dd80a76d9dc3
tree2f9d0fbc1b5da3a128299efedcaaa12e30d28cb9
parentf34242975fae1468dd94d31289d27f68853a28fb
load_contents(): don't try to mmap an empty file

We don't actually create zero-length `packed-refs` files, but they are
valid and we should handle them correctly. The old code `xmmap()`ed
such files, which led to an error when `munmap()` was called. So, if
the `packed-refs` file is empty, leave the snapshot at its zero values
and return 0 without trying to read or mmap the file.

Returning 0 also makes `create_snapshot()` exit early, which avoids
the technically undefined comparison `NULL < NULL`.

Reported-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/packed-backend.c