From: Ivan Maidanski Date: Sat, 17 Dec 2016 14:21:40 +0000 (+0300) Subject: Workaround 'bad address arithmetic' static analysis tool false positive X-Git-Tag: v7.6.2~262 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d56af65332ed54500899a74439bd30985d5b209;p=gc 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. --- diff --git a/os_dep.c b/os_dep.c index 23c8663b..8016542b 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 */ {