Fixed #4036 (cppcheck hangs with 100% cpu load)
This commit is contained in:
parent
7975ffba21
commit
41797d409d
|
@ -1001,13 +1001,17 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
|||
}
|
||||
|
||||
if (line.compare(0, 8, "#define ") == 0) {
|
||||
bool valid = true;
|
||||
bool valid = false;
|
||||
for (std::string::size_type pos = 8; pos < line.size(); ++pos) {
|
||||
char ch = line[pos];
|
||||
if (ch=='_' || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (pos>8 && ch>='0' && ch<='9'))
|
||||
if (ch=='_' || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (pos>8 && ch>='0' && ch<='9')) {
|
||||
valid = true;
|
||||
continue;
|
||||
if (ch==' ' || ch=='(')
|
||||
break;
|
||||
}
|
||||
if (ch==' ' || ch=='(') {
|
||||
if (valid)
|
||||
break;
|
||||
}
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -232,7 +232,8 @@ private:
|
|||
TEST_CASE(testPreprocessorRead3);
|
||||
TEST_CASE(testPreprocessorRead4);
|
||||
|
||||
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
|
||||
TEST_CASE(invalid_define_1); // #2605 - hang for: '#define ='
|
||||
TEST_CASE(invalid_define_2); // #4036 - hang for: '#define () {(int f(x) }'
|
||||
|
||||
// Show 'missing include' warnings
|
||||
TEST_CASE(missingInclude);
|
||||
|
@ -2955,7 +2956,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void invalid_define() {
|
||||
void invalid_define_1() {
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(&settings, this);
|
||||
|
||||
|
@ -2966,6 +2967,17 @@ private:
|
|||
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
||||
}
|
||||
|
||||
void invalid_define_2() { // #4036 - hang
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(&settings, this);
|
||||
|
||||
std::istringstream src("#define () {(int f(x) }\n");
|
||||
std::string processedFile;
|
||||
std::list<std::string> cfg;
|
||||
std::list<std::string> paths;
|
||||
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
||||
}
|
||||
|
||||
void missingInclude() {
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(&settings, this);
|
||||
|
|
Loading…
Reference in New Issue