summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/malloctest/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/libtests/malloctest/init.c')
-rw-r--r--testsuites/libtests/malloctest/init.c72
1 files changed, 65 insertions, 7 deletions
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index a33764177d..d72f49112e 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -1,12 +1,31 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/*
* COPYRIGHT (c) 1989-2011, 2014.
* On-Line Applications Research Corporation (OAR).
*
- * Copyright (c) 2009, 2016 embedded brains GmbH.
+ * Copyright (C) 2009, 2016 embedded brains GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
@@ -41,8 +60,15 @@ static void test_realloc(void)
for (i=2 ; i<2048 ; i++) {
p2 = realloc(p1, i);
if (p2 != p1)
+/*
+ * This was added to address the following warning.
+ * warning: pointer 'p1' may be used after 'realloc'
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wuse-after-free"
printf( "realloc - failed grow in place: "
"%p != realloc(%p,%zu)\n", p1, p2, i);
+#pragma GCC diagnostic pop
p1 = p2;
}
free(p1);
@@ -52,8 +78,15 @@ static void test_realloc(void)
for (i=2047 ; i>=1; i--) {
p2 = realloc(p1, i);
if (p2 != p1)
- printf( "realloc - failed shrink in place: "
+/*
+ * This was added to address the following warning.
+ * warning: pointer 'p1' may be used after 'realloc'
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+ printf( "realloc - failed shrink in place: "
"%p != realloc(%p,%zu)\n", p1, p2, i);
+#pragma GCC diagnostic pop
p1 = p2;
}
free(p1);
@@ -65,8 +98,15 @@ static void test_realloc(void)
p2 = malloc(32);
p3 = realloc(p1, 64);
if (p3 == p1 || p3 == NULL)
- printf(
+/*
+ * This was added to address the following warning.
+ * warning: pointer may be used after 'realloc'
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+ printf(
"realloc - failed non-in place: realloc(%p,%d) = %p\n", p1, 64, p3);
+#pragma GCC diagnostic pop
free(p3);
free(p2);
@@ -103,7 +143,14 @@ static void test_realloc(void)
/*
* Realloc with a bad pointer to force a point
*/
- p4 = realloc( test_realloc, 32 );
+/*
+ * This was added to address the following warning.
+ * warning: 'realloc' called on unallocated object
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
+ p4 = realloc( test_realloc, 32 );
+#pragma GCC diagnostic pop
p4 = _realloc_r( NULL, NULL, 1 );
}
@@ -122,9 +169,13 @@ static void test_heap_default_init(void)
static void test_free( void *addr )
{
+ uint32_t failed_allocs;
+
rtems_test_assert( _Heap_Free( &TestHeap, addr ) );
+ failed_allocs = TestHeap.stats.failed_allocs;
_Heap_Protection_free_all_delayed_blocks( &TestHeap );
+ rtems_test_assert( failed_allocs == TestHeap.stats.failed_allocs );
}
static void test_heap_cases_1(void)
@@ -1505,8 +1556,15 @@ static void test_early_malloc( void )
free( q );
+/*
+ * This was added to address the following warning.
+ * warning: pointer 'q' used after 'free'
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wuse-after-free"
r = realloc( q, 128 );
rtems_test_assert( r == q );
+#pragma GCC diagnostic pop
s = malloc( 1 );
rtems_test_assert( s != NULL );