diff options
Diffstat (limited to '')
-rw-r--r-- | testsuites/libtests/malloctest/init.c | 72 | ||||
-rw-r--r-- | testsuites/libtests/malloctest/system.h | 25 | ||||
-rw-r--r-- | testsuites/libtests/malloctest/task1.c | 27 |
3 files changed, 110 insertions, 14 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 ); diff --git a/testsuites/libtests/malloctest/system.h b/testsuites/libtests/malloctest/system.h index 53a13fc1d6..adf3f4a678 100644 --- a/testsuites/libtests/malloctest/system.h +++ b/testsuites/libtests/malloctest/system.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /* system.h * * This include file contains information that is included in every @@ -6,9 +8,26 @@ * COPYRIGHT (c) 1989-1999. * On-Line Applications Research Corporation (OAR). * - * 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. + * 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. + * + * 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. */ #include <tmacros.h> diff --git a/testsuites/libtests/malloctest/task1.c b/testsuites/libtests/malloctest/task1.c index 753a74e77a..4feb338b87 100644 --- a/testsuites/libtests/malloctest/task1.c +++ b/testsuites/libtests/malloctest/task1.c @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /* task1.c * * This set of three tasks do some simple task switching for about @@ -6,9 +8,26 @@ * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * - * 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. + * 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. + * + * 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 @@ -34,7 +53,7 @@ rtems_task Task_1_through_5( unsigned char *mem_ptr; int mem_amt; - status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); + status = rtems_task_ident( RTEMS_WHO_AM_I, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident" ); while (TRUE) |