Added checking to prevent a rare crash when getting
the name for an external variable in the IR.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@147178 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index 2c0d8ba..c16e126 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -1831,19 +1831,27 @@
          global != end;
          ++global)
     {
+        if (!global)
+        {
+            if (m_error_stream)
+                m_error_stream->Printf("Internal error [IRForTarget]: global variable is NULL");
+            
+            return false;
+        }
+        
+        std::string global_name = (*global).getName().str();
+        
         if (log)
             log->Printf("Examining %s, DeclForGlobalValue returns %p", 
-                        (*global).getName().str().c_str(),
+                        global_name.c_str(),
                         DeclForGlobal(global));
-    
-        std::string global_name = (*global).getName().str();
         
         if (global_name.find("OBJC_IVAR") == 0)
         {
             if (!HandleSymbol(global))
             {
                 if (m_error_stream)
-                    m_error_stream->Printf("Error [IRForTarget]: Couldn't find Objective-C indirect ivar symbol %s\n", (*global).getName().str().c_str());
+                    m_error_stream->Printf("Error [IRForTarget]: Couldn't find Objective-C indirect ivar symbol %s\n", global_name.c_str());
                 
                 return false;
             }
@@ -1863,7 +1871,7 @@
             if (!MaybeHandleVariable (global))
             {
                 if (m_error_stream)
-                    m_error_stream->Printf("Internal error [IRForTarget]: Couldn't rewrite external variable %s\n", (*global).getName().str().c_str());
+                    m_error_stream->Printf("Internal error [IRForTarget]: Couldn't rewrite external variable %s\n", global_name.c_str());
                 
                 return false;
             }