From 71d1c4df4b297b7707b30f84e2a2a026a6e4b345 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 19 Oct 2018 21:13:19 +0300 Subject: [PATCH] Workaround 'condition my_chunk_ptr is always false' cppcheck false positive * src/atomic_ops_malloc.c (get_chunk): Move get_mmaped() call into the for loop; replace return statement inside the loop with break. --- src/atomic_ops_malloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/atomic_ops_malloc.c b/src/atomic_ops_malloc.c index 7e4bbb3f..955ff225 100644 --- a/src/atomic_ops_malloc.c +++ b/src/atomic_ops_malloc.c @@ -230,17 +230,17 @@ get_chunk(void) } if (AO_EXPECT_FALSE(my_chunk_ptr - AO_initial_heap - > AO_INITIAL_HEAP_SIZE - CHUNK_SIZE)) + > AO_INITIAL_HEAP_SIZE - CHUNK_SIZE)) { + /* We failed. The initial heap is used up. */ + my_chunk_ptr = get_mmaped(CHUNK_SIZE); + assert(((AO_t)my_chunk_ptr & (ALIGNMENT-1)) == 0); break; + } if (AO_compare_and_swap(&initial_heap_ptr, (AO_t)my_chunk_ptr, (AO_t)(my_chunk_ptr + CHUNK_SIZE))) { - return my_chunk_ptr; + break; } } - - /* We failed. The initial heap is used up. */ - my_chunk_ptr = get_mmaped(CHUNK_SIZE); - assert (!((AO_t)my_chunk_ptr & (ALIGNMENT-1))); return my_chunk_ptr; }