mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user