]> granicus.if.org Git - libatomic_ops/commitdiff
Workaround 'argument to function assert is always 1' cppcheck warnings
authorIvan Maidanski <ivmai@mail.ru>
Wed, 19 Dec 2018 09:12:34 +0000 (12:12 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 25 Jan 2019 21:38:35 +0000 (00:38 +0300)
* src/atomic_ops_malloc.c (get_chunk): Skip assertion about
my_chunk_ptr value alignment if CPPCHECK.
* tests/test_malloc.c (DEFAULT_NTHREADS): Add comment about the
maximum value.
* tests/test_malloc.c (main): Remove assertion of nthreads value which
is set to DEFAULT_NTHREADS (ideally there should be a static_assert).
* tests/test_stack.c (main): Likewise.

src/atomic_ops_malloc.c
tests/test_malloc.c
tests/test_stack.c

index 955ff22567e50a35cb8dde1c7137716ba4d6a312..07962d3e86fbc92e07cb154d7e6d28f4f5c243e4 100644 (file)
@@ -233,7 +233,9 @@ get_chunk(void)
                         > 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);
+#     if !defined(CPPCHECK)
+        assert(((AO_t)my_chunk_ptr & (ALIGNMENT-1)) == 0);
+#     endif
       break;
     }
     if (AO_compare_and_swap(&initial_heap_ptr, (AO_t)my_chunk_ptr,
index fd95a8fa820010104f01604fe5e82253b70ad519..7888ba8a98b9416f2e83b03cc041731850fe0a3c 100644 (file)
@@ -27,7 +27,7 @@
 
 #ifndef DEFAULT_NTHREADS
 # ifdef HAVE_MMAP
-#   define DEFAULT_NTHREADS 16
+#   define DEFAULT_NTHREADS 16 /* must be <= MAX_NTHREADS */
 # else
 #   define DEFAULT_NTHREADS 3
 # endif
@@ -229,7 +229,6 @@ int main(int argc, char **argv) {
 
     if (1 == argc) {
       nthreads = DEFAULT_NTHREADS;
-      assert(nthreads <= MAX_NTHREADS);
     } else if (2 == argc) {
       nthreads = atoi(argv[1]);
       if (nthreads < 1 || nthreads > MAX_NTHREADS) {
index b42a0057db25a09688235274a927f4ff90a3ab7a..efe59e18d938a503c7ceb013db8247658f1004d4 100644 (file)
@@ -226,7 +226,6 @@ int main(int argc, char **argv)
   if (1 == argc)
     {
       max_nthreads = DEFAULT_NTHREADS;
-      assert(max_nthreads <= MAX_NTHREADS);
     }
   else if (2 == argc)
     {