Fix "Out of memory? mmap failed" for files larger than 4GB on Windows
The git_mmap implementation was broken for file sizes that wouldn't fit into a size_t (32 bits). This was caused by intermediate variables that were only 32 bits wide when they should be 64 bits. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ian McLean committed
May 20, 2010 at 20:57 UTC
60890cc60ccfc7000791a47f1f3d69fdb8884dd7
1 file changed
+3
-3
compat/win32mmap.c
+3
-3
@@ -4,19 +4,19 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
4
{
5
HANDLE hmap;
6
void *temp;
7
- size_t len;
7
+ off_t len;
8
struct stat st;
9
uint64_t o = offset;
10
uint32_t l = o & 0xFFFFFFFF;
11
uint32_t h = (o >> 32) & 0xFFFFFFFF;
12
13
if (!fstat(fd, &st))
14
- len = xsize_t(st.st_size);
14
+ len = st.st_size;
15
else
16
die("mmap: could not determine filesize");
17
18
if ((length + offset) > len)
19
- length = len - offset;
19
+ length = xsize_t(len - offset);
20
21
if (!(flags & MAP_PRIVATE))
22
die("Invalid usage of mmap when built with USE_WIN32_MMAP");