Fixed #2982 (false positive: using char type as array index (using string as key))
This commit is contained in:
parent
2150995475
commit
003956e42e
|
@ -2916,11 +2916,14 @@ void CheckOther::checkCharVariable()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string temp = "%var% [ " + tok->str() + " ]";
|
if (!isPointer)
|
||||||
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
|
|
||||||
{
|
{
|
||||||
charArrayIndexError(tok2->next());
|
std::string temp = "%var% [ " + tok->str() + " ]";
|
||||||
break;
|
if ((tok2->str() != ".") && Token::Match(tok2->next(), temp.c_str()))
|
||||||
|
{
|
||||||
|
charArrayIndexError(tok2->next());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok2, "[;{}] %var% = %any% [&|] %any% ;"))
|
if (Token::Match(tok2, "[;{}] %var% = %any% [&|] %any% ;"))
|
||||||
|
|
|
@ -91,6 +91,12 @@ private:
|
||||||
" buf[ch] = 0;\n"
|
" buf[ch] = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Using char type as array index\n", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue