From 485170cdb1b634b550cf227f4642dcb38097b80c Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Thu, 25 Mar 2021 16:32:46 +0000 Subject: [PATCH] libctf, dump: do not emit size or alignment if it would error When we dump normal types, we emit their size and/or alignment: but size and alignment dumping can return errors if the type is part of a chain that terminates in a forward. Emitting 0xffffffff as a size or alignment is unhelpful, so simply skip emitting this info for any type for which size or alignment checks return an error, no matter what the error is. libctf/ChangeLog 2021-03-25 Nick Alcock * ctf-dump.c (ctf_dump_format_type): Don't emit size or alignment on error. --- libctf/ChangeLog | 5 +++++ libctf/ctf-dump.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 59f6fb042a0..909c4fc87b5 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,8 @@ +2021-03-25 Nick Alcock + + * ctf-dump.c (ctf_dump_format_type): Don't emit size or alignment + on error. + 2021-03-21 Alan Modra * ctf-impl.h: Include string.h. diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c index 8540212eadd..bd9b50d9479 100644 --- a/libctf/ctf-dump.c +++ b/libctf/ctf-dump.c @@ -100,6 +100,7 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag) ctf_encoding_t ep; ctf_arinfo_t ar; int kind, unsliced_kind; + ssize_t size, align; const char *nonroot_leader = ""; const char *nonroot_trailer = ""; const char *idstr = ""; @@ -180,10 +181,10 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag) bit = NULL; } - if (kind != CTF_K_FUNCTION && kind != CTF_K_FORWARD) + size = ctf_type_size (fp, id); + if (kind != CTF_K_FUNCTION && size >= 0) { - if (asprintf (&bit, " (size 0x%lx)", - (unsigned long) ctf_type_size (fp, id)) < 0) + if (asprintf (&bit, " (size 0x%lx)", (unsigned long int) size) < 0) goto oom; str = str_append (str, bit); @@ -191,10 +192,11 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag) bit = NULL; } - if (kind != CTF_K_FORWARD) + align = ctf_type_align (fp, id); + if (align >= 0) { if (asprintf (&bit, " (aligned at 0x%lx)", - (unsigned long) ctf_type_align (fp, id)) < 0) + (unsigned long int) align) < 0) goto oom; str = str_append (str, bit); -- 2.30.2