aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/Diagnostic.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-04-20 06:13:16 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-04-20 06:13:16 +0000
commite46e354ecb9a04c8d3724ae2b0f95f4424e3f69c (patch)
treee8cd4660ee98d2e465f4e20e480d49f25c41e88d /lib/Basic/Diagnostic.cpp
parent65a795bb30ee35ddfbf3b9f400c170b32baaf37b (diff)
Don't crash in the diagnostic printer if we happen to get passed a
null string / identifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69575 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Diagnostic.cpp')
-rw-r--r--lib/Basic/Diagnostic.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 9986fc5a41..d5d8da1e22 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -714,6 +714,11 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
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 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
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('\'');