public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tests: varlocs workaround format-overflow errors
@ 2021-12-04 21:27 Mark Wielaard
  2021-12-08 23:17 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2021-12-04 21:27 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

In function ‘printf’,
    inlined from ‘handle_attr’ at varlocs.c:932:3:
error: ‘%s’ directive argument is null [-Werror=format-overflow=]

The warning is technically correct. A %s argument should not be
NULL. Although in practice all implementations will print it as
"(null)". Workaround this by simply changing the dwarf string
functions to return an "<unknown>" string. The test is for the correct
names, either "(null)" or "<unknown>" would make it fail (also remove
a now unnecessary assert, the switch statement will check for unknown
opcodes anyway).

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog | 10 ++++++++++
 tests/varlocs.c | 11 +++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 9dceda89..a5673f18 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,13 @@
+2021-12-04  Mark Wielaard  <mark@klomp.org>
+
+	* varlocs.c (dwarf_encoding_string): Return "<unknown encoding>" instead
+	of NULL.
+	(dwarf_tag_string): Return "<unknown tag>" instead of NULL.
+	(dwarf_attr_string): Return "<unknown attr>" instead of NULL.
+	(dwarf_form_string): Return "<unknown form>" instead of NULL.
+	(dwarf_opcode_string): Return "<unknown opcode>" instead of NULL.
+	(print_expr): Remove assert.
+
 2021-11-18  Mark Wielaard  <mark@klomp.org>
 
 	* Makefile.am (dwfl_proc_attach_LDFLAGS): Add -rdynamic.
diff --git a/tests/varlocs.c b/tests/varlocs.c
index 152c6555..d2c13767 100644
--- a/tests/varlocs.c
+++ b/tests/varlocs.c
@@ -76,7 +76,7 @@ dwarf_encoding_string (unsigned int code)
   if (likely (code < sizeof (known) / sizeof (known[0])))
     return known[code];
 
-  return NULL;
+  return "<unknown encoding>";
 }
 
 static const char *
@@ -88,7 +88,7 @@ dwarf_tag_string (unsigned int tag)
       DWARF_ALL_KNOWN_DW_TAG
 #undef DWARF_ONE_KNOWN_DW_TAG
     default:
-      return NULL;
+      return "<unknown tag>";
     }
 }
 
@@ -101,7 +101,7 @@ dwarf_attr_string (unsigned int attrnum)
       DWARF_ALL_KNOWN_DW_AT
 #undef DWARF_ONE_KNOWN_DW_AT
     default:
-      return NULL;
+      return "<unknown attr>";
     }
 }
 
@@ -114,7 +114,7 @@ dwarf_form_string (unsigned int form)
       DWARF_ALL_KNOWN_DW_FORM
 #undef DWARF_ONE_KNOWN_DW_FORM
     default:
-      return NULL;
+      return "<unknown form>";
     }
 }
 
@@ -160,7 +160,7 @@ dwarf_opcode_string (unsigned int code)
   if (likely (code < sizeof (known) / sizeof (known[0])))
     return known[code];
 
-  return NULL;
+  return "<unknown opcode>";
 }
 
 // Forward reference for print_expr_block.
@@ -198,7 +198,6 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr, int depth)
 
   uint8_t atom = expr->atom;
   const char *opname = dwarf_opcode_string (atom);
-  assert (opname != NULL);
 
   switch (atom)
     {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tests: varlocs workaround format-overflow errors
  2021-12-04 21:27 [PATCH] tests: varlocs workaround format-overflow errors Mark Wielaard
@ 2021-12-08 23:17 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2021-12-08 23:17 UTC (permalink / raw)
  To: elfutils-devel

On Sat, Dec 04, 2021 at 10:27:29PM +0100, Mark Wielaard wrote:
> In function ‘printf’,
>     inlined from ‘handle_attr’ at varlocs.c:932:3:
> error: ‘%s’ directive argument is null [-Werror=format-overflow=]
> 
> The warning is technically correct. A %s argument should not be
> NULL. Although in practice all implementations will print it as
> "(null)". Workaround this by simply changing the dwarf string
> functions to return an "<unknown>" string. The test is for the correct
> names, either "(null)" or "<unknown>" would make it fail (also remove
> a now unnecessary assert, the switch statement will check for unknown
> opcodes anyway).

Pushed,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-08 23:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-04 21:27 [PATCH] tests: varlocs workaround format-overflow errors Mark Wielaard
2021-12-08 23:17 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).