From 271f4aa1f1334277cd5e052003fc795d4e3ebbc8 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 27 Mar 2001 17:41:01 +0000 Subject: [PATCH] Mapping of zero-length files returns just a random non-zero address. With this fix, empty indices are generated correctly. --- lib/mmap.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/mmap.c b/lib/mmap.c index e461e1ee..87a2047f 100644 --- a/lib/mmap.c +++ b/lib/mmap.c @@ -32,9 +32,14 @@ mmap_file(byte *name, unsigned *len, int writeable) { if (len) *len = st.st_size; - x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); - if (x == MAP_FAILED) - x = NULL; + if (st.st_size) + { + x = mmap(NULL, st.st_size, writeable ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_SHARED, fd, 0); + if (x == MAP_FAILED) + x = NULL; + } + else /* For empty file, we can return any non-zero address */ + return ""; } close(fd); return x; -- 2.39.2