[cfe-commits] r69575 - /cfe/trunk/lib/Basic/Diagnostic.cpp

Daniel Dunbar daniel at zuster.org
Sun Apr 19 23:13:16 PDT 2009


Author: ddunbar
Date: Mon Apr 20 01:13:16 2009
New Revision: 69575

URL: http://llvm.org/viewvc/llvm-project?rev=69575&view=rev
Log:
Don't crash in the diagnostic printer if we happen to get passed a
null string / identifier.

Modified:
    cfe/trunk/lib/Basic/Diagnostic.cpp

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=69575&r1=69574&r2=69575&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Mon Apr 20 01:13:16 2009
@@ -714,6 +714,11 @@
     case Diagnostic::ak_c_string: {
       const char *S = getArgCStr(ArgNo);
       assert(ModifierLen == 0 && "No modifiers for strings yet");
+
+      // Don't crash if get passed a null pointer by accident.
+      if (!S)
+        S = "(null)";
+      
       OutStr.append(S, S + strlen(S));
       break;
     }
@@ -757,6 +762,14 @@
     case Diagnostic::ak_identifierinfo: {
       const IdentifierInfo *II = getArgIdentifier(ArgNo);
       assert(ModifierLen == 0 && "No modifiers for strings yet");
+
+      // Don't crash if get passed a null pointer by accident.
+      if (!II) {
+        const char *S = "(null)";
+        OutStr.append(S, S + strlen(S));
+        continue;
+      }
+
       OutStr.push_back('\'');
       OutStr.append(II->getName(), II->getName() + II->getLength());
       OutStr.push_back('\'');





More information about the cfe-commits mailing list