[PATCH v2 6/6] testsuites/libtests/malloctest: fix warnings

Matthew Joyce matthew.joyce at embedded-brains.de
Fri Jun 10 13:34:59 UTC 2022


From: Matt Joyce <matthew.joyce at embedded-brains.de>

Edited tests to fix new gcc 12 warnings.

Updates #4662
---
 testsuites/libtests/malloctest/init.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index 05d97a27d5..ee8bd8ca52 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -60,8 +60,7 @@ static void test_realloc(void)
   for (i=2 ; i<2048 ; i++) {
     p2 = realloc(p1, i);
     if (p2 != p1)
-      printf( "realloc - failed grow in place: "
-              "%p != realloc(%p,%zu)\n", p1, p2, i);
+      printf( "realloc - failed grow in place\n");
     p1 = p2;
   }
   free(p1);
@@ -71,8 +70,7 @@ static void test_realloc(void)
   for (i=2047 ; i>=1; i--)  {
     p2 = realloc(p1, i);
     if (p2 != p1)
-      printf( "realloc - failed shrink in place: "
-              "%p != realloc(%p,%zu)\n", p1, p2, i);
+      printf( "realloc - failed shrink in place\n");
     p1 = p2;
   }
   free(p1);
@@ -85,7 +83,7 @@ static void test_realloc(void)
   p3 = realloc(p1, 64);
   if (p3 == p1 || p3 == NULL)
     printf(
-      "realloc - failed non-in place: realloc(%p,%d) = %p\n", p1, 64, p3);
+      "realloc - failed non-in place\n");
   free(p3);
   free(p2);
 
@@ -120,11 +118,17 @@ static void test_realloc(void)
   _Thread_Dispatch_enable( _Per_CPU_Get() );
 
   /*
-   *  Realloc with a bad pointer to force a point
+   *  Realloc with a pointer that is not in the heap.
+   *  The error should be detected and NULL should be returned.
    */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfree-nonheap-object"
   p4 = realloc( test_realloc, 32 );
-
+  rtems_test_assert(p4 == NULL);
+#pragma GCC diagnostic pop
   p4 = _realloc_r( NULL, NULL, 1 );
+  rtems_test_assert(p4 != NULL);
+  free(p4);
 }
 
 #define TEST_HEAP_SIZE 2048
@@ -1528,8 +1532,8 @@ static void test_early_malloc( void )
 
   free( q );
 
-  r = realloc( q, 128 );
-  rtems_test_assert( r == q );
+  r = realloc( NULL, 128 );
+  rtems_test_assert( r != NULL );
 
   s = malloc( 1 );
   rtems_test_assert( s != NULL );
-- 
2.31.1



More information about the devel mailing list