#5717 Segmentation fault when providing multiple --include=/path/to/header arguments.

This commit is contained in:
Alexander Mai 2014-04-23 20:50:16 +02:00
parent aea528c763
commit 9412f9d216
2 changed files with 15 additions and 1 deletions

View File

@ -2283,7 +2283,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
// If endfile is encountered, we have moved to a next file in our stack,
// so remove last path in our list.
while ((endfilePos = code.find("\n#endfile", endfilePos)) != std::string::npos && endfilePos < pos) {
while (!paths.empty() && (endfilePos = code.find("\n#endfile", endfilePos)) != std::string::npos && endfilePos < pos) {
paths.pop_back();
endfilePos += 9; // size of #endfile
}

View File

@ -300,6 +300,8 @@ private:
TEST_CASE(validateCfg);
TEST_CASE(if_sizeof);
TEST_CASE(double_include); // #5717
}
@ -4021,6 +4023,18 @@ private:
preprocessor.preprocess(istr, actual, "file.c");
ASSERT_EQUALS("\nFred & Wilma\n\n\n\n\n", actual[""]);
}
void double_include() {
const char code[] = "int x";
Preprocessor preprocessor(nullptr, this);
std::list<std::string> includePaths;
includePaths.push_back(".");
includePaths.push_back(".");
std::map<std::string,std::string> defs;
std::set<std::string> pragmaOnce;
preprocessor.handleIncludes(code, "123.h", includePaths, defs, pragmaOnce, std::list<std::string>());
}
};
REGISTER_TEST(TestPreprocessor)