Browse Source

AutoGen: Don't iterate over a container while populating it.

The InitializeAutogenTarget creates new targets and adds them to the
Targets container on the makefile.  In this method, we have a reference
to that container and we are iterating over it.  That happens to work
with hash_map, but it fails with undefined behavior when using the
std::unordered_map from libstdc++-4.9 (and likely others).
Stephen Kelly 10 years ago
parent
commit
921d74d855
1 changed files with 9 additions and 1 deletions
  1. 9 1
      Source/cmGlobalGenerator.cxx

+ 9 - 1
Source/cmGlobalGenerator.cxx

@@ -1373,10 +1373,18 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets(AutogensType &autogens)
     {
     cmTargets& targets =
       this->LocalGenerators[i]->GetMakefile()->GetTargets();
+    std::vector<std::string> targetNames;
+    targetNames.reserve(targets.size());
     for(cmTargets::iterator ti = targets.begin();
         ti != targets.end(); ++ti)
       {
-      cmTarget& target = ti->second;
+      targetNames.push_back(ti->second.GetName());
+      }
+    for(std::vector<std::string>::iterator ti = targetNames.begin();
+        ti != targetNames.end(); ++ti)
+      {
+      cmTarget& target = *this->LocalGenerators[i]
+                              ->GetMakefile()->FindTarget(*ti, true);
       if(target.GetType() == cmTarget::EXECUTABLE ||
          target.GetType() == cmTarget::STATIC_LIBRARY ||
          target.GetType() == cmTarget::SHARED_LIBRARY ||