Fixed crash in Variable::evaluate (#3825)
This commit is contained in:
parent
df48b8dfb9
commit
e8dfe2407a
|
@ -1550,7 +1550,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
const Token* endTok = NULL;
|
const Token* endTok = NULL;
|
||||||
const Token* nameTok = NULL;
|
const Token* nameTok = NULL;
|
||||||
|
|
||||||
while (tok->str() != "," && tok->str() != ")" && tok->str() != "=") {
|
if (tok->str() == "," || tok->str() == ")")
|
||||||
|
return; // Syntax error
|
||||||
|
|
||||||
|
do {
|
||||||
if (tok->varId() != 0) {
|
if (tok->varId() != 0) {
|
||||||
nameTok = tok;
|
nameTok = tok;
|
||||||
endTok = tok->previous();
|
endTok = tok->previous();
|
||||||
|
@ -1569,7 +1572,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
|
|
||||||
if (!tok) // something is wrong so just bail
|
if (!tok) // something is wrong so just bail
|
||||||
return;
|
return;
|
||||||
}
|
} while (tok->str() != "," && tok->str() != ")" && tok->str() != "=");
|
||||||
|
|
||||||
const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0);
|
const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0);
|
||||||
if (typeTok->str() == "struct")
|
if (typeTok->str() == "struct")
|
||||||
|
|
|
@ -109,6 +109,7 @@ private:
|
||||||
|
|
||||||
TEST_CASE(functionArgs1);
|
TEST_CASE(functionArgs1);
|
||||||
TEST_CASE(functionArgs2);
|
TEST_CASE(functionArgs2);
|
||||||
|
TEST_CASE(functionArgs3);
|
||||||
|
|
||||||
TEST_CASE(namespaces1);
|
TEST_CASE(namespaces1);
|
||||||
TEST_CASE(namespaces2);
|
TEST_CASE(namespaces2);
|
||||||
|
@ -786,6 +787,12 @@ private:
|
||||||
ASSERT_EQUALS(4UL, a->dimension(1));
|
ASSERT_EQUALS(4UL, a->dimension(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void functionArgs3() {
|
||||||
|
GET_SYMBOL_DB("void f(int i,) { }"); // Don't crash
|
||||||
|
const Variable *a = db->getVariableFromVarId(1);
|
||||||
|
ASSERT_EQUALS("i", a->nameToken()->str());
|
||||||
|
}
|
||||||
|
|
||||||
void namespaces1() {
|
void namespaces1() {
|
||||||
GET_SYMBOL_DB("namespace fred {\n"
|
GET_SYMBOL_DB("namespace fred {\n"
|
||||||
" namespace barney {\n"
|
" namespace barney {\n"
|
||||||
|
|
Loading…
Reference in New Issue