]> git.ipfire.org Git - thirdparty/git.git/commitdiff
compat: let git_mmap use malloc(3) directly
authorRené Scharfe <l.s.r@web.de>
Sat, 21 Aug 2021 12:52:40 +0000 (14:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Aug 2021 21:43:45 +0000 (14:43 -0700)
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>
compat/mmap.c

index 14d31010dfe57e520c6864df4f84ea732018785f..8d6c02d4bccc0160e69d3c0892946bfc79f10d00 100644 (file)
@@ -7,7 +7,12 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
        if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
                die("Invalid usage of mmap when built with NO_MMAP");
 
-       start = xmalloc(length);
+       if (length == 0) {
+               errno = EINVAL;
+               return MAP_FAILED;
+       }
+
+       start = malloc(length);
        if (start == NULL) {
                errno = ENOMEM;
                return MAP_FAILED;