Skip to content

Commit 9412f9d

Browse files
committed
danmar#5717 Segmentation fault when providing multiple --include=/path/to/header arguments.
1 parent aea528c commit 9412f9d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
22832283

22842284
// If endfile is encountered, we have moved to a next file in our stack,
22852285
// so remove last path in our list.
2286-
while ((endfilePos = code.find("\n#endfile", endfilePos)) != std::string::npos && endfilePos < pos) {
2286+
while (!paths.empty() && (endfilePos = code.find("\n#endfile", endfilePos)) != std::string::npos && endfilePos < pos) {
22872287
paths.pop_back();
22882288
endfilePos += 9; // size of #endfile
22892289
}

test/testpreprocessor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ class TestPreprocessor : public TestFixture {
300300
TEST_CASE(validateCfg);
301301

302302
TEST_CASE(if_sizeof);
303+
304+
TEST_CASE(double_include); // #5717
303305
}
304306

305307

@@ -4021,6 +4023,18 @@ class TestPreprocessor : public TestFixture {
40214023
preprocessor.preprocess(istr, actual, "file.c");
40224024
ASSERT_EQUALS("\nFred & Wilma\n\n\n\n\n", actual[""]);
40234025
}
4026+
4027+
void double_include() {
4028+
const char code[] = "int x";
4029+
4030+
Preprocessor preprocessor(nullptr, this);
4031+
std::list<std::string> includePaths;
4032+
includePaths.push_back(".");
4033+
includePaths.push_back(".");
4034+
std::map<std::string,std::string> defs;
4035+
std::set<std::string> pragmaOnce;
4036+
preprocessor.handleIncludes(code, "123.h", includePaths, defs, pragmaOnce, std::list<std::string>());
4037+
}
40244038
};
40254039

40264040
REGISTER_TEST(TestPreprocessor)

0 commit comments

Comments
 (0)