From b491afa0faff470a7d18080ece757342b9805e82 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Wed, 22 Oct 2025 12:17:53 +0200 Subject: [PATCH] readelf: use PRIu16 instead of PRId16 for uint16_t 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/readelf.c b/src/readelf.c index 49d19a80..ee6c203d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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); } -- 2.47.3