From c82a4fe5aecdf71b931adb353540956edbc27498 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 17 Dec 2016 17:21:40 +0300 Subject: [PATCH] Workaround 'bad address arithmetic' static analysis tool false positive The tool complains whether (alloc(size)+ofs) is intentional instead of (alloc(size+ofs)). In our case, it is a false alarm (the offset is added to the result to align the allocation at HBLKSIZE boundary). * os_dep.c [USE_WINALLOC && MSWIN32] (GC_win32_get_mem): Store result of GlobalAlloc() to "result" local variable first (then, perform result alignment in a standalone statement); add comment. --- os_dep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/os_dep.c b/os_dep.c index 8bceee5..ca0b989 100644 --- a/os_dep.c +++ b/os_dep.c @@ -2306,8 +2306,10 @@ void * os2_alloc(size_t bytes) /* VirtualAlloc doesn't like PAGE_EXECUTE_READWRITE. */ /* There are also unconfirmed rumors of other */ /* problems, so we dodge the issue. */ - result = (ptr_t)(((word)GlobalAlloc(0, SIZET_SAT_ADD(bytes, HBLKSIZE)) - + HBLKSIZE - 1) & ~(word)(HBLKSIZE - 1)); + result = (ptr_t)GlobalAlloc(0, SIZET_SAT_ADD(bytes, HBLKSIZE)); + /* Align it at HBLKSIZE boundary. */ + result = (ptr_t)(((word)result + HBLKSIZE - 1) + & ~(word)(HBLKSIZE - 1)); } else # endif /* else */ { -- 2.7.4