Fixed #1094 (Improve check: unusual pointer arithmetic: 'ch+str')
This commit is contained in:
parent
cd5b95849d
commit
2d5d060514
|
@ -820,7 +820,7 @@ void CheckOther::strPlusChar()
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Declaring char variable..
|
// Declaring char variable..
|
||||||
if (Token::Match(tok, "char %var% [;=]"))
|
if (Token::Match(tok, "char|int|short %var% [;=]"))
|
||||||
{
|
{
|
||||||
unsigned int varid = tok->next()->varId();
|
unsigned int varid = tok->next()->varId();
|
||||||
if (varid > 0 && varid < 10000)
|
if (varid > 0 && varid < 10000)
|
||||||
|
|
|
@ -431,10 +431,19 @@ private:
|
||||||
// Strange looking pointer arithmetic..
|
// Strange looking pointer arithmetic..
|
||||||
strPlusChar("void foo()\n"
|
strPlusChar("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char ch = '/';\n"
|
" char ch = 1;\n"
|
||||||
" const char *p = \"/usr\" + ch;\n"
|
" const char *p = ch + \"/usr\";\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Unusual pointer arithmetic\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// Strange looking pointer arithmetic..
|
||||||
|
strPlusChar("void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int i = 1;\n"
|
||||||
|
" const char* psz = \"Bla\";\n"
|
||||||
|
" const std::string str = i + psz;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void strPlusChar3()
|
void strPlusChar3()
|
||||||
|
|
Loading…
Reference in New Issue