[glibc] Use correct type for glibc.malloc.perturb in tst-tunconf1.c

Stefan Liebler via Glibc-cvs <[email protected]> Tue, 14 Jul 2026 08:00:23 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=202b4f794aa38370aaf03a0e28a2eb2a21877072

commit 202b4f794aa38370aaf03a0e28a2eb2a21877072
Author: Stefan Liebler <[email protected]>
Date:   Mon Jul 13 10:31:53 2026 +0200

    Use correct type for glibc.malloc.perturb in tst-tunconf1.c
    
    On s390x the test elf/tunconf1 fails with:
    tst-tunconf1.c:41: numeric comparison failure (widths 64 and 32)
       left: 180388626436 (0x2a00000004); from: (long)perturb
      right: 42 (0x2a); from: 42
    
    According to elf/dl-tunables.list, glibc.malloc.perturb is of type int32_t (4byte)
    and not size_t (8byte) which was used for TUNABLE_GET_FULL inside the testcase.
    Therefore the correct 32bit value 0x2a=42 is written to the to the wrong place
    and leads to the comparison failure.
    
    The printf format specifiers for size_t were also adjusted.
    Reviewed-by: DJ Delorie <[email protected]>

Diff:
---
 elf/tst-tunconf1.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/elf/tst-tunconf1.c b/elf/tst-tunconf1.c
index 2d245de84f..c7e4151d73 100644
--- a/elf/tst-tunconf1.c
+++ b/elf/tst-tunconf1.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <inttypes.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <support/check.h>
@@ -27,28 +28,28 @@ do_test (void)
 {
   size_t tcache_count = TUNABLE_GET_FULL (glibc, malloc, tcache_count, size_t, NULL);
   size_t tcache_max = TUNABLE_GET_FULL (glibc, malloc, tcache_max, size_t, NULL);
-  size_t perturb = TUNABLE_GET_FULL (glibc, malloc, perturb, size_t, NULL);
+  int32_t perturb = TUNABLE_GET_FULL (glibc, malloc, perturb, int32_t, NULL);
   size_t mmap_threshold = TUNABLE_GET_FULL (glibc, malloc, mmap_threshold, size_t, NULL);
   size_t trim_threshold = TUNABLE_GET_FULL (glibc, malloc, trim_threshold, size_t, NULL);
 
-  printf("tcache count is %ld (should be 5, from env)\n", (long)tcache_count);
+  printf("tcache count is %zu (should be 5, from env)\n", tcache_count);
   TEST_COMPARE ((long)tcache_count, 5);
-  printf("tcache max is %ld (should be 4, from /etc)\n", (long)tcache_max);
+  printf("tcache max is %zu (should be 4, from /etc)\n", tcache_max);
   TEST_COMPARE ((long)tcache_max, 4);
 
   /* This is set by the environment but blocked by the config.  */
-  printf("perturb is %ld (should be 42, from /etc)\n",
-	 (long)perturb);
-  TEST_COMPARE ((long)perturb, 42);
+  printf("perturb is %" PRId32 " (should be 42, from /etc)\n",
+	 perturb);
+  TEST_COMPARE (perturb, 42);
 
   /* This is blocked by the general config, enabled by filter, set in env.  */
-  printf("mmap_threshold is %ld (should be 10002, from env)\n",
-	 (long)mmap_threshold);
+  printf("mmap_threshold is %zu (should be 10002, from env)\n",
+	 mmap_threshold);
   TEST_COMPARE ((long)mmap_threshold, 10002);
 
   /* This is allowed by the general config, blocked by filter, set in env.  */
-  printf("trim_threshold is %ld (should be 10001, from filter)\n",
-	 (long)trim_threshold);
+  printf("trim_threshold is %zu (should be 10001, from filter)\n",
+	 trim_threshold);
   TEST_COMPARE ((long)trim_threshold, 10001);
 
   /* Interaction with legacy environment-variable aliases (MALLOC_*).  */
@@ -58,20 +59,20 @@ do_test (void)
 
   /* Overridable cache default (100); the MALLOC_MMAP_MAX_ alias overrides
      it, just like GLIBC_TUNABLES would.  */
-  printf("mmap_max is %d (should be 200, from MALLOC_MMAP_MAX_ alias)\n",
+  printf("mmap_max is %" PRId32 " (should be 200, from MALLOC_MMAP_MAX_ alias)"
+	 "\n",
 	 mmap_max);
   TEST_COMPARE (mmap_max, 200);
 
   /* Nonoverridable cache default (100); the MALLOC_TOP_PAD_ alias must not
      override it.  */
-  printf("top_pad is %ld (should be 100, from /etc nonoverridable)\n",
-	 (long)top_pad);
+  printf("top_pad is %zu (should be 100, from /etc nonoverridable)\n",
+	 top_pad);
   TEST_COMPARE ((long)top_pad, 100);
 
   /* Set both by GLIBC_TUNABLES (300) and by the MALLOC_ARENA_MAX alias
      (400); the canonical GLIBC_TUNABLES form wins.  */
-  printf("arena_max is %ld (should be 300, from GLIBC_TUNABLES)\n",
-	 (long)arena_max);
+  printf("arena_max is %zu (should be 300, from GLIBC_TUNABLES)\n", arena_max);
   TEST_COMPARE ((long)arena_max, 300);
 
   return 0;