Fixed ticket #3721 (false positive: syntax error on valid C code ( K&R function style )).

This commit is contained in:
Edoardo Prezioso 2012-04-22 01:56:40 +02:00
parent 710fefeef0
commit be5a61b794
2 changed files with 15 additions and 15 deletions

View File

@ -5311,20 +5311,27 @@ bool Tokenizer::simplifyFunctionParameters()
tok1 = tok1->next();
}
if (bailOut) {
if (bailOut || !tok1) {
tok = tok->link();
continue;
}
//the two containers should hold the same size..
//the two containers may not hold the same size...
//in that case, the missing parameters are defined as 'int'
if (argumentNames.size() != argumentNames2.size()) {
tok = tok->link();
//error if the second container is not empty
if (!argumentNames2.empty()) {
syntaxError(tok);
return false;
//move back 'tok1' to the last ';'
tok1 = tok1->previous();
std::map<std::string, Token *>::iterator it;
for (it = argumentNames.begin(); it != argumentNames.end(); ++it) {
if (argumentNames2.find(it->first) == argumentNames2.end()) {
//add the missing parameter argument declaration
tok1->insertToken(";");
tok1->insertToken(it->first);
//register the change inside argumentNames2
argumentNames2[it->first] = tok1->next();
tok1->insertToken("int");
}
}
continue;
}
while (tok->str() != ")") {

View File

@ -4088,13 +4088,6 @@ private:
tokenizeAndStringify("void foo(int, int)\n"
"{}\n");
ASSERT_EQUALS("", errout.str());
//non-matching arguments after round braces
tokenizeAndStringify("void foo(x, y, z)\n"
" int x;\n"
" int y;\n"
"{}\n");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
// Simplify "((..))" into "(..)"