Skip to content

Commit 95b4ff3

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebf3c04 commit 95b4ff3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compat/mmap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
77
if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ)
88
die("Invalid usage of mmap when built with NO_MMAP");
99

10-
start = xmalloc(length);
10+
if (length == 0) {
11+
errno = EINVAL;
12+
return MAP_FAILED;
13+
}
14+
15+
start = malloc(length);
1116
if (start == NULL) {
1217
errno = ENOMEM;
1318
return MAP_FAILED;

0 commit comments

Comments
 (0)