Fix segfault in variableIsUsedInScope() - loop variable not check against NULL

This commit is contained in:
Alexander Mai 2014-03-22 11:14:11 +01:00
parent e1c565357a
commit 6a08c27183
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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)