diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index 258edc5a8..3198298c1 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -189,7 +189,8 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname // 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% (" ) ) { // Don't make recursive checking.. diff --git a/CheckOther.cpp b/CheckOther.cpp index 354f3a5ee..f51110599 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -637,6 +637,7 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[ // Check if the variable is used in this indentlevel.. bool used = false, used1 = false; int indentlevel = 0; + int parlevel = 0; bool for_or_while = false; 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 ) { 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 ) for_or_while = true; - if ( tok->str[0] == ';' ) + if ( parlevel == 0 && tok->str[0] == ';' ) for_or_while = false; } diff --git a/tests.cpp b/tests.cpp index 36869f065..b830f1656 100644 --- a/tests.cpp +++ b/tests.cpp @@ -952,9 +952,24 @@ static void unused_variable() " f(i);\n" " }\n" " }\n" - "}\n"; + "}\n"; 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, "" ); + + + + }