[08/10] libctf: fix signed/unsigned comparison confusion

Message ID 20210227132954.7766-9-nick.alcock@oracle.com
State New
Headers show
Series
  • libctf: cleanups, speedups, and bugfixes (one needing review)
Related show

Commit Message

H.J. Lu via Binutils Feb. 27, 2021, 1:29 p.m.
Comparing an encoding's cte_bits to a ctf_type_size needs a cast:
one is a uint32_t and the other is an ssize_t.

libctf/ChangeLog
2021-02-25  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dump.c (ctf_dump_format_type): Fix signed/unsigned confusion.
---
 libctf/ChangeLog  | 4 ++++
 libctf/ctf-dump.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

-- 
2.30.0.252.gc27e85e57d

Patch

diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 1f3176c5549..01286bcab54 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,7 @@ 
+2021-02-25  Nick Alcock  <nick.alcock@oracle.com>
+
+	* ctf-dump.c (ctf_dump_format_type): Fix signed/unsigned confusion.
+
 2021-02-25  Nick Alcock  <nick.alcock@oracle.com>
 
 	* ctf-dedup.c (ctf_dedup): Pass on errors from ctf_dedup_hash_type.
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 758d28d76d5..788355d9db1 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -144,7 +144,7 @@  ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
 
       if (ctf_type_encoding (fp, id, &ep) == 0)
 	{
-	  if (ep.cte_bits != ctf_type_size (fp, id) * CHAR_BIT
+	  if ((ssize_t) ep.cte_bits != ctf_type_size (fp, id) * CHAR_BIT
 	      && flag & CTF_FT_BITFIELD)
 	    {
 	      if (asprintf (&bit, ":%i", ep.cte_bits) < 0)
@@ -154,7 +154,7 @@  ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
 	      bit = NULL;
 	    }
 
-	  if (ep.cte_bits != ctf_type_size (fp, id) * CHAR_BIT
+	  if ((ssize_t) ep.cte_bits != ctf_type_size (fp, id) * CHAR_BIT
 	      || ep.cte_offset != 0)
 	    {
 	      const char *slice = "";