Fixed #2982 (false positive: using char type as array index (using string as key))

This commit is contained in:
Daniel Marjamäki 2011-08-09 17:03:22 +02:00
parent 2150995475
commit 003956e42e
2 changed files with 13 additions and 4 deletions

View File

@ -2916,11 +2916,14 @@ void CheckOther::checkCharVariable()
break;
}
std::string temp = "%var% [ " + tok->str() + " ]";
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
if (!isPointer)
{
charArrayIndexError(tok2->next());
break;
std::string temp = "%var% [ " + tok->str() + " ]";
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
{
charArrayIndexError(tok2->next());
break;
}
}
if (Token::Match(tok2, "[;{}] %var% = %any% [&|] %any% ;"))

View File

@ -91,6 +91,12 @@ private:
" buf[ch] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Using char type as array index\n", errout.str());
check("void foo(const char str[])\n"
"{\n"
" map[str] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}