|
33 | 33 |
|
34 | 34 | #include "xml.h" |
35 | 35 |
|
| 36 | +// Not XMLDocument::LoadFile(): with MSVC it denies writing, and addons inherit the handle (#15207) |
| 37 | +static tinyxml2::XMLError loadFile(tinyxml2::XMLDocument &doc, const std::string &filename) |
| 38 | +{ |
| 39 | + std::ifstream fin(filename, std::ios::binary); |
| 40 | + if (!fin.is_open()) |
| 41 | + return tinyxml2::XML_ERROR_FILE_NOT_FOUND; |
| 42 | + std::ostringstream ostr; |
| 43 | + ostr << fin.rdbuf(); |
| 44 | + const std::string data = ostr.str(); |
| 45 | + return doc.Parse(data.data(), data.size()); |
| 46 | +} |
| 47 | + |
36 | 48 | AnalyzerInformation::~AnalyzerInformation() |
37 | 49 | { |
38 | 50 | close(); |
@@ -81,7 +93,7 @@ std::set<std::string> AnalyzerInformation::getIncludes(const std::string &buildD |
81 | 93 | const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir, sourcefile, cfg, fsFileId); |
82 | 94 |
|
83 | 95 | tinyxml2::XMLDocument analyzerInfoDoc; |
84 | | - if (analyzerInfoDoc.LoadFile(analyzerInfoFile.c_str()) != tinyxml2::XML_SUCCESS) |
| 96 | + if (loadFile(analyzerInfoDoc, analyzerInfoFile) != tinyxml2::XML_SUCCESS) |
85 | 97 | return files; |
86 | 98 |
|
87 | 99 | const tinyxml2::XMLElement *const rootNode = analyzerInfoDoc.FirstChildElement(); |
@@ -239,7 +251,7 @@ bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::st |
239 | 251 |
|
240 | 252 | { |
241 | 253 | tinyxml2::XMLDocument analyzerInfoDoc; |
242 | | - const tinyxml2::XMLError xmlError = analyzerInfoDoc.LoadFile(analyzerInfoFile.c_str()); |
| 254 | + const tinyxml2::XMLError xmlError = loadFile(analyzerInfoDoc, analyzerInfoFile); |
243 | 255 | if (xmlError == tinyxml2::XML_SUCCESS) { |
244 | 256 | const std::string err = skipAnalysis(analyzerInfoDoc, hash, errors); |
245 | 257 | if (err.empty()) { |
@@ -324,7 +336,7 @@ std::string AnalyzerInformation::processFilesTxt(const std::string& buildDir, co |
324 | 336 | const std::string xmlfile = buildDir + '/' + filesTxtInfo.afile; |
325 | 337 |
|
326 | 338 | tinyxml2::XMLDocument doc; |
327 | | - const tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str()); |
| 339 | + const tinyxml2::XMLError error = loadFile(doc, xmlfile); |
328 | 340 | if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) { |
329 | 341 | /* FIXME: this can currently not be reported as an error because: |
330 | 342 | * - --clang does not generate any analyzer information - see #14456 |
|
0 commit comments