Refactoring of 'CheckBufferOverrun.cpp'

This commit is contained in:
Daniel Marjamäki 2008-03-24 19:32:17 +00:00
parent 41252ac45a
commit fcff7a4052
2 changed files with 23 additions and 4 deletions

View File

@ -259,7 +259,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
// Function call.. // Function call..
// Todo: Handle struct member variables.. // Todo: Handle struct member variables..
if ( varc == 0 && match( tok, "var (" ) ) if ( match( tok, "var (" ) )
{ {
// Don't make recursive checking.. // Don't make recursive checking..
if (std::find(CallStack.begin(), CallStack.end(), tok) != CallStack.end()) if (std::find(CallStack.begin(), CallStack.end(), tok) != CallStack.end())
@ -290,8 +290,8 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
if ( parlevel == 1 && if ( parlevel == 1 &&
strchr( "(,", *getstr(tok2,0) ) && strchr( "(,", *getstr(tok2,0) ) &&
strcmp( varname[0], getstr(tok2, 1) ) == 0 && Match1( tok2->next, "%var1%", varname ) &&
strchr( ",)", *getstr(tok2,2) ) ) strchr( ",)", *getstr(tok2, 2+varc) ) )
{ {
par++; par++;
break; break;
@ -320,7 +320,7 @@ static void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname
else if ( ftok->str[0] == ',' ) else if ( ftok->str[0] == ',' )
par--; par--;
else if (par==1 && parlevel==1 && (match(ftok,"var ,") || match(ftok,"var )"))) else if (par==1 && parlevel==1 && (match(ftok, "var ,") || match(ftok, "var )")))
{ {
// Parameter name.. // Parameter name..
const char *parname[2]; const char *parname[2];

View File

@ -431,6 +431,25 @@ static void buffer_overrun()
check( CheckBufferOverrun, __LINE__, test11, "[test.cpp:9] -> [test.cpp:3]: Array index out of bounds\n" ); check( CheckBufferOverrun, __LINE__, test11, "[test.cpp:9] -> [test.cpp:3]: Array index out of bounds\n" );
const char test12[] = "struct ABC\n"
"{\n"
" char str[10];\n"
"};\n"
"\n"
"static void memclr( char *data )\n"
"{\n"
" data[10] = 0;\n"
"}\n"
"\n"
"static void f(ABC *abc)\n"
"{\n"
" memclr(abc->str);\n"
"}\n";
check( CheckBufferOverrun, __LINE__, test12, "[test.cpp:13] -> [test.cpp:8]: Array index out of bounds\n" );
// TODO // TODO
/* /*