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

Message ID 20240814125649.47119-9-dodji@redhat.com
State New
Headers
Series [01/11] Use smart pointers for variables exported from the ABI corpus |

Commit Message

Dodji Seketeli Aug. 14, 2024, 12:56 p.m. UTC
  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(-)
  

Patch

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);
   }