diff options
| author | Richard Trieu <rtrieu@google.com> | 2015-01-08 01:27:03 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2015-01-08 01:27:03 +0000 |
| commit | b3b8bb002918d786408f4a1368725bbc14802876 (patch) | |
| tree | d35ab6e97682dbc4c2c64c8d40c99e8752d58c70 /clang/lib | |
| parent | a799e2e0146e95ced5f7a4520e84a97311e69d47 (diff) | |
| download | bcm5719-llvm-b3b8bb002918d786408f4a1368725bbc14802876.tar.gz bcm5719-llvm-b3b8bb002918d786408f4a1368725bbc14802876.zip | |
When the diagnostic text is simply "%0", sanitize the string for any
unprintable characters. Fixes PR22048.
llvm-svn: 225423
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index a8929466084..83228ad3c55 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/Support/Locale.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -629,6 +630,20 @@ void Diagnostic:: FormatDiagnostic(const char *DiagStr, const char *DiagEnd, SmallVectorImpl<char> &OutStr) const { + // When the diagnostic string is only "%0", the entire string is being given + // by an outside source. Remove unprintable characters from this string + // and skip all the other string processing. + if (DiagEnd - DiagStr == 2 && DiagStr[0] == '%' && DiagStr[1] == '0' && + getArgKind(0) == DiagnosticsEngine::ak_std_string) { + const std::string &S = getArgStdStr(0); + for (char c : S) { + if (llvm::sys::locale::isPrint(c) || c == '\t') { + OutStr.push_back(c); + } + } + return; + } + /// FormattedArgs - Keep track of all of the arguments formatted by /// ConvertArgToString and pass them into subsequent calls to /// ConvertArgToString, allowing the implementation to avoid redundancies in |

