From d64a49fdc61024e01d0de810b9cc9205be3e02e5 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Wed, 3 Dec 2014 14:29:00 +0300 Subject: [PATCH] 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: Andrey Vagin Signed-off-by: Pavel Emelyanov --- test/zdtm/live/transition/maps007.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/zdtm/live/transition/maps007.c b/test/zdtm/live/transition/maps007.c index 21960efad..53b0b4c6c 100644 --- a/test/zdtm/live/transition/maps007.c +++ b/test/zdtm/live/transition/maps007.c @@ -12,8 +12,8 @@ #include "zdtmtst.h" #include "lock.h" -#define MAP_SIZE (1 << 20) -#define MEM_SIZE (1 << 29) +#define MAP_SIZE (1UL << 20) +#define MEM_SIZE (1UL << 29) #define PAGE_SIZE 4096 const char *test_doc = "create random mappings and touch memory"; @@ -93,7 +93,8 @@ int main(int argc, char **argv) count++; p = start + ((lrand48() * PAGE_SIZE) % MEM_SIZE); - size = (lrand48() * PAGE_SIZE) % (end - p); + size = lrand48() * PAGE_SIZE; + size %= (end - p); size %= MAP_SIZE; if (size == 0) size = PAGE_SIZE;