Fix #808 (Segfault in Preprocessor)
http://sourceforge.net/apps/trac/cppcheck/ticket/808
This commit is contained in:
parent
e52c36788f
commit
ea36632ca3
|
@ -1222,10 +1222,10 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filename
|
|||
|
||||
// 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("#endfile", endfilePos)) != std::string::npos && endfilePos < pos)
|
||||
while ((endfilePos = code.find("\n#endfile", endfilePos)) != std::string::npos && endfilePos < pos)
|
||||
{
|
||||
paths.pop_back();
|
||||
endfilePos += 8; // size of #endfile
|
||||
endfilePos += 9; // size of #endfile
|
||||
}
|
||||
|
||||
endfilePos = pos;
|
||||
|
|
|
@ -156,6 +156,7 @@ private:
|
|||
|
||||
// define and then ifdef
|
||||
TEST_CASE(define_ifdef);
|
||||
TEST_CASE(endfile);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1602,6 +1603,23 @@ private:
|
|||
TODO_ASSERT_EQUALS(1, actual.size());
|
||||
}
|
||||
}
|
||||
|
||||
void endfile()
|
||||
{
|
||||
const char filedata[] = "char a[] = \"#endfile\";\n"
|
||||
"char b[] = \"#endfile\";\n"
|
||||
"#include \"notfound.h\"\n";
|
||||
|
||||
// Preprocess => actual result..
|
||||
std::istringstream istr(filedata);
|
||||
std::map<std::string, std::string> actual;
|
||||
Preprocessor preprocessor;
|
||||
preprocessor.preprocess(istr, actual, "file.c");
|
||||
|
||||
// Compare results..
|
||||
ASSERT_EQUALS("char a[] = \"#endfile\";\nchar b[] = \"#endfile\";\n\n", actual[""]);
|
||||
ASSERT_EQUALS(1, actual.size());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestPreprocessor)
|
||||
|
|
Loading…
Reference in New Issue