TestCharVar: Fixed some false positives

This commit is contained in:
Daniel Marjamäki 2008-11-02 16:29:36 +00:00
parent 7d234fd5c2
commit ffa8e3d0b6
2 changed files with 16 additions and 5 deletions

View File

@ -685,15 +685,15 @@ void CheckCharVariable()
break; break;
} }
else if ( Match(tok2, "%var% [ %var1% ]", varname) ) if (!Match(tok2,".") && Match(tok2->next, "%var% [ %var1% ]", varname))
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << FileLine(tok2) << ": Warning - using char variable as array index"; errmsg << FileLine(tok2->next) << ": Warning - using char variable as array index";
ReportErr(errmsg.str()); ReportErr(errmsg.str());
break; break;
} }
else if ( Match(tok2, "[&|] %var1%", varname) || Match(tok2, "%var1% [&|]", varname) ) if ( Match(tok2, "%var% [&|] %var1%", varname) || Match(tok2, "%var1% [&|]", varname) )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << FileLine(tok2) << ": Warning - using char variable in bit operation"; errmsg << FileLine(tok2) << ": Warning - using char variable in bit operation";

View File

@ -37,7 +37,8 @@ private:
void run() void run()
{ {
TEST_CASE( array_index ); TEST_CASE( array_index );
TEST_CASE( bitop ); TEST_CASE( bitop1 );
TEST_CASE( bitop2 );
} }
void check( const char code[] ) void check( const char code[] )
@ -82,7 +83,7 @@ private:
} }
void bitop() void bitop1()
{ {
check( "void foo()\n" check( "void foo()\n"
"{\n" "{\n"
@ -91,6 +92,16 @@ private:
"}\n" ); "}\n" );
ASSERT_EQUALS( std::string("[test.cpp:4]: Warning - using char variable in bit operation\n"), errout.str() ); ASSERT_EQUALS( std::string("[test.cpp:4]: Warning - using char variable in bit operation\n"), errout.str() );
} }
void bitop2()
{
check( "void foo()\n"
"{\n"
" char ch;\n"
" func(&ch);\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
}; };
REGISTER_TEST( TestCharVar ) REGISTER_TEST( TestCharVar )