]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: use PRIu16 instead of PRId16 for uint16_t
authorAndreas Schwab <schwab@suse.de>
Wed, 22 Oct 2025 10:17:53 +0000 (12:17 +0200)
committerAaron Merey <amerey@redhat.com>
Wed, 22 Oct 2025 21:57:00 +0000 (17:57 -0400)
The Elfxx_Half type is unsigned, thus it should be printed as an unsigned
type.  This fixes the formatting of such a value if it is bigger than
32767, which would be printed as a negative number with the PRId16 format,
due to a recent change in glibc that properly converts the value to the
narrow type before printing.

Fixes this testsuite failure:

@@ -14,7 +14,7 @@
   Flags:
   Size of this header:               64 (bytes)
   Size of program header entries:    56 (bytes)
-  Number of program headers entries: -1 (66000 in [0].sh_info)
+  Number of program headers entries: 65535 (66000 in [0].sh_info)
   Size of section header entries:    64 (bytes)
   Number of section headers entries: 1
   Section header string table index: 0
FAIL run-getphdrnum.sh (exit status: 1)

src/readelf.c

index 49d19a805fc31c89be2c34352ae224ff8c07d1af..ee6c203d0acc2f1353a714067dad347f639efcb3 100644 (file)
@@ -1377,13 +1377,13 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
   printf (_("  Flags:                             %s\n"),
          ebl_machine_flag_name (ebl, ehdr->e_flags, buf, sizeof (buf)));
 
-  printf (_("  Size of this header:               %" PRId16 " %s\n"),
+  printf (_("  Size of this header:               %" PRIu16 " %s\n"),
          ehdr->e_ehsize, _("(bytes)"));
 
-  printf (_("  Size of program header entries:    %" PRId16 " %s\n"),
+  printf (_("  Size of program header entries:    %" PRIu16 " %s\n"),
          ehdr->e_phentsize, _("(bytes)"));
 
-  printf (_("  Number of program headers entries: %" PRId16),
+  printf (_("  Number of program headers entries: %" PRIu16),
          ehdr->e_phnum);
   if (ehdr->e_phnum == PN_XNUM)
     {
@@ -1397,10 +1397,10 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
     }
   fputc ('\n', stdout);
 
-  printf (_("  Size of section header entries:    %" PRId16 " %s\n"),
+  printf (_("  Size of section header entries:    %" PRIu16 " %s\n"),
          ehdr->e_shentsize, _("(bytes)"));
 
-  printf (_("  Number of section headers entries: %" PRId16),
+  printf (_("  Number of section headers entries: %" PRIu16),
          ehdr->e_shnum);
   if (ehdr->e_shnum == 0)
     {
@@ -1432,7 +1432,7 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
              buf);
     }
   else
-    printf (_("  Section header string table index: %" PRId16 "\n\n"),
+    printf (_("  Section header string table index: %" PRIu16 "\n\n"),
            ehdr->e_shstrndx);
 }