diff options
author | Ryan Long <ryan.long@oarcorp.com> | 2022-08-16 12:04:00 -0500 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2022-08-19 15:34:47 -0500 |
commit | a447b9b377ac77e0cd9604b61451821967cf017d (patch) | |
tree | 3bb0933625554b956edf0317ed08d419833d2622 /testsuites/libtests | |
parent | dl09/dl-load.c: Fix gcc 12 warning (diff) | |
download | rtems-a447b9b377ac77e0cd9604b61451821967cf017d.tar.bz2 |
malloctest/init.c: Added pragmas to address gcc 12 warnings
Updates #4662
Diffstat (limited to 'testsuites/libtests')
-rw-r--r-- | testsuites/libtests/malloctest/init.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c index 05d97a27d5..ae3719c2cd 100644 --- a/testsuites/libtests/malloctest/init.c +++ b/testsuites/libtests/malloctest/init.c @@ -60,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); @@ -71,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); @@ -84,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); @@ -122,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 ); } @@ -1528,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 ); |