Fixed ticket #403 (false positive::Array index out of range)

http://sourceforge.net/apps/trac/cppcheck/ticket/403
This commit is contained in:
Slava Semushin 2009-06-14 11:21:20 +07:00
parent 3e045dcf37
commit 084b3c002f
2 changed files with 21 additions and 8 deletions

View File

@ -703,7 +703,8 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
}
else if (line.find("#file \"") == 0 ||
line.find("#endfile") == 0 ||
line.find("#define") == 0)
line.find("#define") == 0 ||
line.find("#undef") == 0)
{
// We must not remove #file tags or line numbers
// are corrupted. File tags are removed by the tokenizer.
@ -712,7 +713,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
line[0] == '#')
{
// Remove #if, #else, #pragma etc, leaving only
// #define, #file and #endfile. and also lines
// #define, #undef, #file and #endfile. and also lines
// which are not part of this configuration.
line = "";
}

View File

@ -726,13 +726,25 @@ private:
void preprocessor_undef()
{
const char filedata[] = "#define AAA int a;\n"
"#undef AAA\n"
"#define AAA char b=0;\n"
"AAA\n";
{
const char filedata[] = "#define AAA int a;\n"
"#undef AAA\n"
"#define AAA char b=0;\n"
"AAA\n";
// Compare results..
ASSERT_EQUALS("\n\n\nchar b=0;\n", OurPreprocessor::expandMacros(filedata));
// Compare results..
ASSERT_EQUALS("\n\n\nchar b=0;\n", OurPreprocessor::expandMacros(filedata));
}
{
// ticket #403
const char filedata[] = "#define z p[2]\n"
"#undef z\n"
"int z;\n"
"z = 0;\n";
ASSERT_EQUALS("\n\nint z;\nz = 0;\n", OurPreprocessor::getcode(filedata, "", "", NULL));
}
}
void defdef()