summaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-09-14 04:53:42 +0000
committerPeter Palfrader <peter@palfrader.org>2006-09-14 04:53:42 +0000
commit28cac25d7e438c7081e9d2c3ecdf86beb2360ff8 (patch)
treee62286e750180f0d5a973d21e369c528bf1eae30 /src/common/compat.c
parent984e8f6efb9dd50b5848545f12c6c81e4173fe5d (diff)
downloadtor-28cac25d7e438c7081e9d2c3ecdf86beb2360ff8.tar.gz
tor-28cac25d7e438c7081e9d2c3ecdf86beb2360ff8.zip
r9749@danube: weasel | 2006-09-14 06:53:12 +0200
Do not graciously increase the size to be mmaped if the current size already is at a page_size boundary. This is important since if a file has a size of zero and we mmap() it with length > 0, then accessing the mmaped memory area causes a bus error. However, if we pass a length of 0 to mmap() it will return with -1 and things work from there. svn:r8387
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 22acadff2a..674baeca0a 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -130,7 +130,7 @@ tor_mmap_file(const char *filename)
lseek(fd, 0, SEEK_SET);
/* ensure page alignment */
page_size = getpagesize();
- size += (page_size + (page_size-(size%page_size)));
+ size += (size%page_size) ? page_size-(size%page_size) : 0;
string = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0);
if (string == MAP_FAILED) {