From 21545152c81172ebc022459002a90d2546c9ee66 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 4 Dec 2009 13:34:14 +0200 Subject: [PATCH] Fixed false positive mmap return value error checks. Normally a pointer with its topmost bits set may cause false errors due to the fact that such pointers result in negative integer casts. The remedy is to use IS_ERR() macro that accepts only down to -1000 as error and any values below as valid. --- conts/posix/test0/src/mmaptest.c | 2 +- conts/posix/test0/src/mutextest.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conts/posix/test0/src/mmaptest.c b/conts/posix/test0/src/mmaptest.c index 5ff6230..b6e82ec 100644 --- a/conts/posix/test0/src/mmaptest.c +++ b/conts/posix/test0/src/mmaptest.c @@ -33,7 +33,7 @@ int mmaptest(void) if (write(fd, &x, sizeof(x)) < 0) goto out_err; - if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0) + if (IS_ERR(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0))) goto out_err; *(unsigned int *)(base + PAGE_SIZE*2) = 0x1000; diff --git a/conts/posix/test0/src/mutextest.c b/conts/posix/test0/src/mutextest.c index 60669fd..d4f4574 100644 --- a/conts/posix/test0/src/mutextest.c +++ b/conts/posix/test0/src/mutextest.c @@ -49,8 +49,8 @@ int user_mutex_test(void) * Create a shared anonymous memory region. This can be * accessed by both parent and child after a fork. */ - if ((int)(base = mmap(0, map_size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, 0, 0)) < 0) { + if (IS_ERR(base = mmap(0, map_size, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, 0, 0))) { printf("%s: mmap for extended ipc buffer failed: %x\n", __FUNCTION__, (int)base); goto out_err;