[Lldb-commits] [lldb] r219245 - The type category enable * was implemented assuming a previous disable * had happened. While that will most likely be true in practice, the consequences of this not being the case will be a crash. I fix the crash by doing two things: 1) don't let already-enabled categories be enabled anyway; 2) if a category were disabled but with a bogus last-enabled position - highly highly unlikely - just put it in the first empty slot. I am not so sure 2) is bulletproof perfect, but I also don't thin...

Enrico Granata egranata at apple.com
Tue Oct 7 15:15:27 PDT 2014


Author: enrico
Date: Tue Oct  7 17:15:27 2014
New Revision: 219245

URL: http://llvm.org/viewvc/llvm-project?rev=219245&view=rev
Log:
The type category enable * was implemented assuming a previous disable * had happened. While that will most likely be true in practice, the consequences of this not being the case will be a crash. I fix the crash by doing two things: 1) don't let already-enabled categories be enabled anyway; 2) if a category were disabled but with a bogus last-enabled position - highly highly unlikely - just put it in the first empty slot. I am not so sure 2) is bulletproof perfect, but I also don't think 2) will practically ever happen

Modified:
    lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp

Modified: lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp?rev=219245&r1=219244&r2=219245&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp Tue Oct  7 17:15:27 2014
@@ -126,10 +126,25 @@ TypeCategoryMap::EnableAllCategories ()
     std::vector<ValueSP> sorted_categories(m_map.size(), ValueSP());
     MapType::iterator iter = m_map.begin(), end = m_map.end();
     for (; iter != end; ++iter)
-        sorted_categories.at(iter->second->GetLastEnabledPosition()) = iter->second;
+    {
+        if (iter->second->IsEnabled())
+            continue;
+        auto pos = iter->second->GetLastEnabledPosition();
+        if (pos >= sorted_categories.size())
+        {
+            auto iter = std::find_if(sorted_categories.begin(),
+                                     sorted_categories.end(),
+                                     [] (const ValueSP& sp) -> bool {
+                                         return sp.get() == nullptr;
+                                     });
+            pos = std::distance(sorted_categories.begin(), iter);
+        }
+        sorted_categories.at(pos) = iter->second;
+    }
     decltype(sorted_categories)::iterator viter = sorted_categories.begin(), vend = sorted_categories.end();
     for (; viter != vend; viter++)
-        Enable(*viter, Last);
+        if (viter->get())
+            Enable(*viter, Last);
 }
 
 void





More information about the lldb-commits mailing list