From ffa8e3d0b6463740858389fa81cf924f6d6671f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Nov 2008 16:29:36 +0000 Subject: [PATCH] TestCharVar: Fixed some false positives --- CheckOther.cpp | 6 +++--- testcharvar.cpp | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CheckOther.cpp b/CheckOther.cpp index f44aa9d25..efd78d0aa 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -685,15 +685,15 @@ void CheckCharVariable() break; } - else if ( Match(tok2, "%var% [ %var1% ]", varname) ) + if (!Match(tok2,".") && Match(tok2->next, "%var% [ %var1% ]", varname)) { 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()); break; } - else if ( Match(tok2, "[&|] %var1%", varname) || Match(tok2, "%var1% [&|]", varname) ) + if ( Match(tok2, "%var% [&|] %var1%", varname) || Match(tok2, "%var1% [&|]", varname) ) { std::ostringstream errmsg; errmsg << FileLine(tok2) << ": Warning - using char variable in bit operation"; diff --git a/testcharvar.cpp b/testcharvar.cpp index 3308e2dbc..c9b665362 100644 --- a/testcharvar.cpp +++ b/testcharvar.cpp @@ -37,7 +37,8 @@ private: void run() { TEST_CASE( array_index ); - TEST_CASE( bitop ); + TEST_CASE( bitop1 ); + TEST_CASE( bitop2 ); } void check( const char code[] ) @@ -82,7 +83,7 @@ private: } - void bitop() + void bitop1() { check( "void foo()\n" "{\n" @@ -91,6 +92,16 @@ private: "}\n" ); 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 )