Minor updates. Removed some false positives when checking variable scope
This commit is contained in:
parent
89605c0167
commit
60e454fa11
|
@ -189,7 +189,8 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
|
||||||
|
|
||||||
|
|
||||||
// Function call..
|
// Function call..
|
||||||
// Todo: Handle struct member variables..
|
// It's not interesting to check what happens when the whole struct is
|
||||||
|
// sent as the parameter, that is checked separately anyway.
|
||||||
if ( Match( tok, "%var% (" ) )
|
if ( Match( tok, "%var% (" ) )
|
||||||
{
|
{
|
||||||
// Don't make recursive checking..
|
// Don't make recursive checking..
|
||||||
|
|
|
@ -637,6 +637,7 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[
|
||||||
// Check if the variable is used in this indentlevel..
|
// Check if the variable is used in this indentlevel..
|
||||||
bool used = false, used1 = false;
|
bool used = false, used1 = false;
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
|
int parlevel = 0;
|
||||||
bool for_or_while = false;
|
bool for_or_while = false;
|
||||||
while ( indentlevel >= 0 && tok )
|
while ( indentlevel >= 0 && tok )
|
||||||
{
|
{
|
||||||
|
@ -657,6 +658,17 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if ( tok->str[0] == '(' )
|
||||||
|
{
|
||||||
|
parlevel++;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ( tok->str[0] == ')' )
|
||||||
|
{
|
||||||
|
parlevel--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
else if ( strcmp(tok->str, varname) == 0 )
|
else if ( strcmp(tok->str, varname) == 0 )
|
||||||
{
|
{
|
||||||
if ( indentlevel == 0 || used1 )
|
if ( indentlevel == 0 || used1 )
|
||||||
|
@ -668,7 +680,7 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[
|
||||||
{
|
{
|
||||||
if ( strcmp(tok->str,"for")==0 || strcmp(tok->str,"while")==0 )
|
if ( strcmp(tok->str,"for")==0 || strcmp(tok->str,"while")==0 )
|
||||||
for_or_while = true;
|
for_or_while = true;
|
||||||
if ( tok->str[0] == ';' )
|
if ( parlevel == 0 && tok->str[0] == ';' )
|
||||||
for_or_while = false;
|
for_or_while = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
tests.cpp
15
tests.cpp
|
@ -956,5 +956,20 @@ static void unused_variable()
|
||||||
check( CheckVariableScope, __LINE__, test9, "" );
|
check( CheckVariableScope, __LINE__, test9, "" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char test10[] = "static void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" TPoint p1;\n"
|
||||||
|
" for (i=0;i<10;i++)\n"
|
||||||
|
" {\n"
|
||||||
|
" p1=point(i,i);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
check( CheckVariableScope, __LINE__, test10, "" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue