summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:39 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-10-12 13:51:40 -0700
commitae9e6ef35e1c09cb198dcd7b22287c42728663e7 (patch)
treedce5f437e7a17df4528edc1ca6e0837907da1ed7
parentMerge branch 'pw/rebase-r-fixes' into maint (diff)
parentcompat: let git_mmap use malloc(3) directly (diff)
downloadtgif-ae9e6ef35e1c09cb198dcd7b22287c42728663e7.tar.xz
Merge branch 'rs/git-mmap-uses-malloc' into maint
mmap() imitation used to call xmalloc() that dies upon malloc() failure, which has been corrected to just return an error to the caller to be handled. * rs/git-mmap-uses-malloc: compat: let git_mmap use malloc(3) directly
-rw-r--r--compat/mmap.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/compat/mmap.c b/compat/mmap.c
index 14d31010df..8d6c02d4bc 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;