diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-12-08 12:42:30 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-12-08 12:42:30 +0000 |
commit | 2fec65d39437340c9f50fcabb5df96ecb24ec09c (patch) | |
tree | 54c1823056ce90fdb22bbf09f74c79ebd26e3177 /clang/lib/Frontend/TextDiagnosticBuffer.cpp | |
parent | f242d8c31b3d00091d39343e2ebbd1e1ed7ea4bf (diff) | |
download | bcm5719-llvm-2fec65d39437340c9f50fcabb5df96ecb24ec09c.tar.gz bcm5719-llvm-2fec65d39437340c9f50fcabb5df96ecb24ec09c.zip |
Escape % in the TextDiagnosticBuffer so they aren't interpreted twice when fed into the diagnostic formatting machinery again.
Fixes PR14543.
llvm-svn: 169677
Diffstat (limited to 'clang/lib/Frontend/TextDiagnosticBuffer.cpp')
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticBuffer.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Frontend/TextDiagnosticBuffer.cpp b/clang/lib/Frontend/TextDiagnosticBuffer.cpp index 57105f15a30..039475a2e04 100644 --- a/clang/lib/Frontend/TextDiagnosticBuffer.cpp +++ b/clang/lib/Frontend/TextDiagnosticBuffer.cpp @@ -42,17 +42,37 @@ void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, } } +/// \brief Escape diagnostic texts to avoid problems when they are fed into the +/// diagnostic formatter a second time. +static StringRef escapeDiag(StringRef Str, SmallVectorImpl<char> &Buf) { + size_t Pos = Str.find('%'); + if (Pos == StringRef::npos) + return Str; + + // We found a '%'. Replace this and all following '%' with '%%'. + Buf.clear(); + Buf.append(Str.data(), Str.data() + Pos); + for (size_t I = Pos, E = Str.size(); I != E; ++I) { + if (Str[I] == '%') + Buf.push_back('%'); + Buf.push_back(Str[I]); + } + + return StringRef(Buf.data(), Buf.size()); +} + void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { + SmallVector<char, 64> Buf; // FIXME: Flush the diagnostics in order. for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, - it->second.c_str())); + escapeDiag(it->second, Buf))); for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, - it->second.c_str())); + escapeDiag(it->second, Buf))); for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, - it->second.c_str())); + escapeDiag(it->second, Buf))); } DiagnosticConsumer *TextDiagnosticBuffer::clone(DiagnosticsEngine &) const { |