]> granicus.if.org Git - libatomic_ops/commitdiff
Eliminate 'my_chunk_ptr-AO_initial_heap out of bounds' cppcheck warning
authorIvan Maidanski <ivmai@mail.ru>
Wed, 19 Dec 2018 09:26:22 +0000 (12:26 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 25 Jan 2019 21:39:01 +0000 (00:39 +0300)
* src/atomic_ops_malloc.c (get_chunk): Replace p1-p2>limit expression
with (AO_t)p1>(AO_t)(p2+limit), where p1>=p2 and p2+limit does not
overflow.

src/atomic_ops_malloc.c

index 07962d3e86fbc92e07cb154d7e6d28f4f5c243e4..ac6bad3ca5f16bf98212b405c72525fcbd7fcb8b 100644 (file)
@@ -229,8 +229,8 @@ get_chunk(void)
                                     (AO_t)initial_ptr, (AO_t)my_chunk_ptr);
       }
 
-    if (AO_EXPECT_FALSE(my_chunk_ptr - AO_initial_heap
-                        > AO_INITIAL_HEAP_SIZE - CHUNK_SIZE)) {
+    if (AO_EXPECT_FALSE((AO_t)my_chunk_ptr
+            > (AO_t)(AO_initial_heap + AO_INITIAL_HEAP_SIZE - CHUNK_SIZE))) {
       /* We failed.  The initial heap is used up.       */
       my_chunk_ptr = get_mmaped(CHUNK_SIZE);
 #     if !defined(CPPCHECK)