Commit d64a49fd authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm/maps007: don't use signed values in calculations

maps007 segfaults on i386, because "size" is calculated bigger than allowed.

This occurs when the result of lrand48() * PAGE_SIZE is negative.
In this case the % operation returns a negative value too, what is unexpected.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent bda033e1
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "zdtmtst.h" #include "zdtmtst.h"
#include "lock.h" #include "lock.h"
#define MAP_SIZE (1 << 20) #define MAP_SIZE (1UL << 20)
#define MEM_SIZE (1 << 29) #define MEM_SIZE (1UL << 29)
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
const char *test_doc = "create random mappings and touch memory"; const char *test_doc = "create random mappings and touch memory";
...@@ -93,7 +93,8 @@ int main(int argc, char **argv) ...@@ -93,7 +93,8 @@ int main(int argc, char **argv)
count++; count++;
p = start + ((lrand48() * PAGE_SIZE) % MEM_SIZE); p = start + ((lrand48() * PAGE_SIZE) % MEM_SIZE);
size = (lrand48() * PAGE_SIZE) % (end - p); size = lrand48() * PAGE_SIZE;
size %= (end - p);
size %= MAP_SIZE; size %= MAP_SIZE;
if (size == 0) if (size == 0)
size = PAGE_SIZE; size = PAGE_SIZE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment