From: Ted Kremenek Date: Sat, 28 Mar 2009 06:40:54 +0000 (+0000) Subject: Properly escape special characters in 's in plist file. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0b6f726ab78ca32d60c5970777ae1d383d047df;p=clang Properly escape special characters in 's in plist file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67924 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/PlistDiagnostics.cpp b/lib/Frontend/PlistDiagnostics.cpp index ba3c1f1605..007fae8896 100644 --- a/lib/Frontend/PlistDiagnostics.cpp +++ b/lib/Frontend/PlistDiagnostics.cpp @@ -98,6 +98,24 @@ static void EmitRange(llvm::raw_ostream& o, SourceManager* SM, SourceRange R, Indent(o, indent) << "\n"; } +static llvm::raw_ostream& EmitString(llvm::raw_ostream& o, + const std::string& s) { + o << ""; + for (std::string::const_iterator I=s.begin(), E=s.end(); I!=E; ++I) { + char c = *I; + switch (c) { + default: o << c; break; + case '&': o << "&"; break; + case '<': o << "<"; break; + case '>': o << ">"; break; + case '\'': o << "'"; break; + case '\"': o << """; break; + } + } + o << ""; + return o; +} + static void ReportControlFlow(llvm::raw_ostream& o, const PathDiagnosticControlFlowPiece& P, const FIDMap& FM, SourceManager *SM, @@ -138,7 +156,8 @@ static void ReportControlFlow(llvm::raw_ostream& o, // Output any helper text. const std::string& s = P.getString(); if (!s.empty()) { - Indent(o, indent) << "alternate" << s << "\n"; + Indent(o, indent) << "alternate"; + EmitString(o, s) << '\n'; } --indent; @@ -175,12 +194,13 @@ static void ReportEvent(llvm::raw_ostream& o, const PathDiagnosticPiece& P, // Output the text. assert(!P.getString().empty()); Indent(o, indent) << "extended_message\n"; - Indent(o, indent) << "" << P.getString() << "\n"; + Indent(o, indent); + EmitString(o, P.getString()) << '\n'; // Output the short text. // FIXME: Really use a short string. Indent(o, indent) << "message\n"; - Indent(o, indent) << "" << P.getString() << "\n"; + EmitString(o, P.getString()) << '\n'; // Finish up. --indent; @@ -288,8 +308,10 @@ PlistDiagnostics::~PlistDiagnostics() { " \n"; for (llvm::SmallVectorImpl::iterator I=Fids.begin(), E=Fids.end(); - I!=E; ++I) - o << " " << SM->getFileEntryForID(*I)->getName() << "\n"; + I!=E; ++I) { + o << " "; + EmitString(o, SM->getFileEntryForID(*I)->getName()) << '\n'; + } o << " \n" " diagnostics\n" @@ -314,19 +336,19 @@ PlistDiagnostics::~PlistDiagnostics() { o << " \n"; // Output the bug type and bug category. - o << " description" << D->getDescription() - << "\n" - << " category" << D->getCategory() - << "\n" - << " type" << D->getBugType() - << "\n"; + o << " description"; + EmitString(o, D->getDescription()) << '\n'; + o << " category"; + EmitString(o, D->getCategory()) << '\n'; + o << " type"; + EmitString(o, D->getBugType()) << '\n'; // Output the location of the bug. o << " location\n"; EmitLocation(o, SM, D->getLocation(), FM, 2); + // Close up the entry. o << " \n"; - } o << " \n";