]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Recursive check guard
authorPetr Machata <pmachata@redhat.com>
Mon, 30 Nov 2009 18:20:26 +0000 (19:20 +0100)
committerPetr Machata <pmachata@redhat.com>
Wed, 18 Aug 2010 12:55:17 +0000 (14:55 +0200)
src/dwarflint/checks.hh

index aba996e918c2bf9785bd4cacb5049073c0c0505b..2db2f05a7a748ead3f5a25ee95a83141b73fe922 100644 (file)
@@ -27,6 +27,7 @@
 #define DWARFLINT_CHECKS_HH
 
 #include <string>
+#include <cassert>
 #include "where.h"
 #include "dwarflint.hh"
 
@@ -65,16 +66,28 @@ dwarflint::check ()
       // We already tried to do the check, but failed.
       if (c == NULL)
        throw check_base::failed ();
+      else
+       // Recursive dependency!
+       assert (c != (T *)-1);
     }
   else
     {
-      // Put a marker there saying that we tried to do the check, but
-      // it failed.
-      if (!_m_checks.insert (std::make_pair (key, (T *)0)).second)
+      // Put a marker there saying that we are trying to satisfy that
+      // dependency.
+      if (!_m_checks.insert (std::make_pair (key, (T *)-1)).second)
        throw std::runtime_error ("duplicate key");
 
       // Now do the check.
-      c = new T (*this);
+      try
+       {
+         c = new T (*this);
+       }
+      catch (...)
+       {
+         // Nope, we failed.  Put the anchor there.
+         _m_checks[key] = NULL;
+         throw;
+       }
 
       // On success, put the actual check object there instead of the
       // marker.