Fix segfault in variableIsUsedInScope() - loop variable not check against NULL
This commit is contained in:
parent
e1c565357a
commit
6a08c27183
|
@ -107,7 +107,7 @@ static bool variableIsUsedInScope(const Token* start, unsigned int varId, const
|
|||
if (!start) // Ticket #5024
|
||||
return false;
|
||||
|
||||
for (const Token *tok = start; tok != scope->classEnd; tok = tok->next()) {
|
||||
for (const Token *tok = start; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->varId() == varId)
|
||||
return true;
|
||||
if (tok->scope()->type == Scope::eFor || tok->scope()->type == Scope::eDo || tok->scope()->type == Scope::eWhile) // In case of loops, better checking would be necessary
|
||||
|
|
|
@ -110,6 +110,8 @@ private:
|
|||
TEST_CASE(returnParameterAddress);
|
||||
|
||||
TEST_CASE(testconstructor); // ticket #5478 - crash
|
||||
|
||||
TEST_CASE(variableIsUsedInScope); // ticket #5599 crash in variableIsUsedInScope()
|
||||
}
|
||||
|
||||
|
||||
|
@ -851,6 +853,16 @@ private:
|
|||
"};");
|
||||
}
|
||||
|
||||
void variableIsUsedInScope() {
|
||||
check("void removed_cb (GList *uids) {\n"
|
||||
"for (; uids; uids = uids->next) {\n"
|
||||
"}\n"
|
||||
"}\n"
|
||||
"void opened_cb () {\n"
|
||||
" g_signal_connect (G_CALLBACK (removed_cb));\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestAutoVariables)
|
||||
|
|
Loading…
Reference in New Issue