From: Daniel Dunbar Date: Mon, 20 Apr 2009 06:13:16 +0000 (+0000) Subject: Don't crash in the diagnostic printer if we happen to get passed a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e46e354ecb9a04c8d3724ae2b0f95f4424e3f69c;p=clang 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 --- 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 &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 &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('\'');