[PATCH 09/11] reader: Avoid crashing on empty scopes in reader::push_decl_to_scope

dodji@redhat.com dodji@redhat.com
Wed Aug 14 12:56:47 GMT 2024


From: Dodji Seketeli <dodji@redhat.com>

When abixml::reader::push_decl_to_scope gets a nullptr scope, it can
sometimes abort.  Fixed thus.

	* src/abg-reader.cc (reader::push_decl_to_scope): It's only if
	there is a non-nil scope that the assert can be reached.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-reader.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 2928f3b3..64d16171 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -802,10 +802,12 @@ public:
   {
     ABG_ASSERT(decl);
     if (scope)
-      add_decl_to_scope(decl, scope);
-    if (!decl->get_translation_unit())
-      decl->set_translation_unit(get_translation_unit());
-    ABG_ASSERT(decl->get_translation_unit());
+      {
+	add_decl_to_scope(decl, scope);
+	if (!decl->get_translation_unit())
+	  decl->set_translation_unit(get_translation_unit());
+	ABG_ASSERT(decl->get_translation_unit());
+      }
     push_decl(decl);
   }
 
-- 
2.43.5



More information about the Libabigail mailing list