diff options
author | René Scharfe <l.s.r@web.de> | 2021-08-21 12:52:40 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-08-24 21:43:45 (GMT) |
commit | 95b4ff3931064ff222e87eecf6af504ba55069d7 (patch) | |
tree | 4a328ce202ecc18389187d82f51164eadde56311 /compat | |
parent | ebf3c04b262aa27fbb97f8a0156c2347fecafafb (diff) | |
download | git-95b4ff3931064ff222e87eecf6af504ba55069d7.zip git-95b4ff3931064ff222e87eecf6af504ba55069d7.tar.gz git-95b4ff3931064ff222e87eecf6af504ba55069d7.tar.bz2 |
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>
Diffstat (limited to 'compat')
-rw-r--r-- | compat/mmap.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compat/mmap.c b/compat/mmap.c index 14d3101..8d6c02d 100644 --- a/compat/mmap.c +++ b/compat/mmap.c @@ -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; |