[Lldb-commits] [lldb] r146540 - in /lldb/trunk: source/API/SBTarget.cpp source/Core/Module.cpp test/python_api/default-constructor/sb_target.py test/python_api/type/TestTypeList.py

Johnny Chen johnny.chen at apple.com
Tue Dec 13 17:43:31 PST 2011


Author: johnny
Date: Tue Dec 13 19:43:31 2011
New Revision: 146540

URL: http://llvm.org/viewvc/llvm-project?rev=146540&view=rev
Log:
http://llvm.org/bugs/show_bug.cgi?id=11560 lldb::SBTarget::FindFirstType crashes when passed None

Add null checks to several functions.  Plus add test scenario for passing None to SBTarget.FindFirstType(None) and friends.

Modified:
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/test/python_api/default-constructor/sb_target.py
    lldb/trunk/test/python_api/type/TestTypeList.py

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=146540&r1=146539&r2=146540&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Dec 13 19:43:31 2011
@@ -1188,7 +1188,7 @@
 {
     if (!append)
         sc_list.Clear();
-    if (m_opaque_sp)
+    if (name && m_opaque_sp)
     {
         const bool symbols_ok = true;
         return m_opaque_sp->GetImages().FindFunctions (ConstString(name), 
@@ -1203,7 +1203,7 @@
 lldb::SBType
 SBTarget::FindFirstType (const char* type)
 {
-    if (m_opaque_sp)
+    if (type && m_opaque_sp)
     {
         size_t count = m_opaque_sp->GetImages().GetSize();
         for (size_t idx = 0; idx < count; idx++)
@@ -1223,7 +1223,7 @@
     
     SBTypeList retval;
     
-    if (m_opaque_sp)
+    if (type && m_opaque_sp)
     {
         ModuleList& images = m_opaque_sp->GetImages();
         ConstString name_const(type);
@@ -1251,7 +1251,7 @@
 {
     SBValueList sb_value_list;
     
-    if (m_opaque_sp)
+    if (name && m_opaque_sp)
     {
         VariableList variable_list;
         const bool append = true;

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=146540&r1=146539&r2=146540&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Dec 13 19:43:31 2011
@@ -506,6 +506,9 @@
 static const char*
 StripTypeName(const char* name_cstr)
 {
+    // Protect against null c string.
+    if (!name_cstr)
+        return name_cstr;
     const char* skip_namespace = strstr(name_cstr, "::");
     const char* template_arg_char = strchr(name_cstr, '<');
     while (skip_namespace != NULL)

Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=146540&r1=146539&r2=146540&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_target.py (original)
+++ lldb/trunk/test/python_api/default-constructor/sb_target.py Tue Dec 13 19:43:31 2011
@@ -24,6 +24,7 @@
     obj.FindFunctions("the_func", 0xff, True, contextlist)
     obj.FindFirstType("dont_care")
     obj.FindTypes("dont_care")
+    obj.FindFirstType(None)
     obj.GetSourceManager()
     obj.FindGlobalVariables("my_global_var", 1)
     address = obj.ResolveLoadAddress(0xffff)

Modified: lldb/trunk/test/python_api/type/TestTypeList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/type/TestTypeList.py?rev=146540&r1=146539&r2=146540&view=diff
==============================================================================
--- lldb/trunk/test/python_api/type/TestTypeList.py (original)
+++ lldb/trunk/test/python_api/type/TestTypeList.py Tue Dec 13 19:43:31 2011
@@ -69,6 +69,10 @@
             self.assertTrue(type)
             self.DebugSBType(type)
 
+        # Pass an empty string.  LLDB should not crash. :-)
+        fuzz_types = target.FindTypes(None)
+        fuzz_type = target.FindFirstType(None)
+
         # Now use the SBTarget.FindFirstType() API to find 'Task'.
         task_type = target.FindFirstType('Task')
         self.assertTrue(task_type)





More information about the lldb-commits mailing list