[19/19] libctf: fix ctf_archive_count return value on big-endian

Message ID 20240730153707.168357-20-nick.alcock@oracle.com
State New
Headers
Series libctf: various bugfixes (including a write into freed memory), and loosen constraints on enums |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Nick Alcock July 30, 2024, 3:37 p.m. UTC
  This failed to properly byteswap its return value.

The ctf_archive format predates the idea of "just write natively and
flip on open", and byteswaps all over the place.  It's too easy to
forget one.  The next revision of the archive format (not versioned,
so we just tweak the magic number instead) should be native-endianned
like the dicts inside it are.

libctf/
	* ctf-archive.c (ctf_archive_count): Byteswap return value.
---
 libctf/ctf-archive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 0034bf0982a..b73999cacb5 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -785,7 +785,7 @@  ctf_archive_count (const ctf_archive_t *wrapper)
   if (!wrapper->ctfi_is_archive)
     return 1;
 
-  return wrapper->ctfi_archive->ctfa_ndicts;
+  return le64toh (wrapper->ctfi_archive->ctfa_ndicts);
 }
 
 /* Look up a symbol in an archive by name or index (if the name is set, a lookup