compat: let git_mmap use malloc(3) directly

xmalloc() dies on error, allows zero-sized allocations and enforces GIT_ALLOC_LIMIT for testing. Our mmap replacement doesn't need any of that. Let's cut out the wrapper, reject zero-sized requests as required by POSIX and use malloc(3) directly. Allocation errors were needlessly handled by git_mmap() before; this code becomes reachable now. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 21, 2021 at 14:52 UTC 95b4ff3931064ff222e87eecf6af504ba55069d7
1 file changed +6 -1
compat/mmap.c
+6 -1
@@ -7,7 +7,12 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
7 if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
8 die("Invalid usage of mmap when built with NO_MMAP");
9
10 - start = xmalloc(length);
10 + if (length == 0) {
11 + errno = EINVAL;
12 + return MAP_FAILED;
13 + }
14 +
15 + start = malloc(length);
16 if (start == NULL) {
17 errno = ENOMEM;
18 return MAP_FAILED;