Ticket #5024: Don't crash upon invalid code when checking auto variables.

This commit is contained in:
Simon Martin 2013-09-28 00:14:12 +02:00
parent 67915749b0
commit d67a0add47
2 changed files with 8 additions and 0 deletions

View File

@ -101,6 +101,9 @@ static bool checkRvalueExpression(const Token * const vartok)
static bool variableIsUsedInScope(const Token* start, unsigned int varId, const Scope *scope)
{
if(!start) // Ticket #5024
return false;
for (const Token *tok = start; tok != scope->classEnd; tok = tok->next()) {
if (tok->varId() == varId)
return true;

View File

@ -78,6 +78,7 @@ private:
TEST_CASE(testautovar9);
TEST_CASE(testautovar10); // ticket #2930 - void f(char *p) { p = '\0'; }
TEST_CASE(testautovar11); // ticket #4641 - fp, assign local struct member address to function parameter
TEST_CASE(testautovar12); // ticket #5024 - crash
TEST_CASE(testautovar_array1);
TEST_CASE(testautovar_array2);
TEST_CASE(testautovar_return1);
@ -325,6 +326,10 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
}
void testautovar12() { // Ticket #5024 - Crash on invalid input
check("void f(int* a) { a = }");
}
void testautovar_array1() {
check("void func1(int* arr[2])\n"