public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tests: Use error, not assert, when trying to print a non-base type DIE.
@ 2018-06-06 21:44 Mark Wielaard
  2018-06-08 14:22 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2018-06-06 21:44 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

When using the varlocs test with a fuzzer using assert for internal
sanity checks is great to find issues. But when encountering bad data
using an assert is wrong. Just use error to show we handle the data
correctly (by reporting it is bad, instead of crashing).

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tests/ChangeLog | 5 +++++
 tests/varlocs.c | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index a7b8da72..587e2ac9 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-06  Mark Wielaard  <mark@klomp.org>
+
+	* varlocs.c (print_base_type): Use error, not assert when the DIE
+	isn't a base type.
+
 2018-06-02  Mark Wielaard  <mark@klomp.org>
 
 	* test-subr.sh (self_test_files_exe): Drop shared libraries.
diff --git a/tests/varlocs.c b/tests/varlocs.c
index 31a1069a..2ddd3d8f 100644
--- a/tests/varlocs.c
+++ b/tests/varlocs.c
@@ -122,7 +122,8 @@ dwarf_form_string (unsigned int form)
 static void
 print_base_type (Dwarf_Die *base)
 {
-  assert (dwarf_tag (base) == DW_TAG_base_type);
+  if (dwarf_tag (base) != DW_TAG_base_type)
+    error (EXIT_FAILURE, 0, "not a base type");
 
   Dwarf_Attribute encoding;
   Dwarf_Word enctype = 0;
-- 
2.17.0

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

* Re: [PATCH] tests: Use error, not assert, when trying to print a non-base type DIE.
  2018-06-06 21:44 [PATCH] tests: Use error, not assert, when trying to print a non-base type DIE Mark Wielaard
@ 2018-06-08 14:22 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2018-06-08 14:22 UTC (permalink / raw)
  To: elfutils-devel

On Wed, 2018-06-06 at 23:43 +0200, Mark Wielaard wrote:
> When using the varlocs test with a fuzzer using assert for internal
> sanity checks is great to find issues. But when encountering bad data
> using an assert is wrong. Just use error to show we handle the data
> correctly (by reporting it is bad, instead of crashing).

Pushed to master.

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

end of thread, other threads:[~2018-06-08 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-06 21:44 [PATCH] tests: Use error, not assert, when trying to print a non-base type DIE Mark Wielaard
2018-06-08 14:22 ` 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).