strPlusChar: Fixed false positives
This commit is contained in:
parent
b1250e1750
commit
f409861492
|
@ -987,17 +987,17 @@ void CheckOther::strPlusChar()
|
|||
}
|
||||
|
||||
//
|
||||
else if (Token::Match(tok, "%str% + %any%"))
|
||||
else if (Token::Match(tok, "[=(] %str% + %any%"))
|
||||
{
|
||||
// char constant..
|
||||
const char *s = tok->strAt(2);
|
||||
const char *s = tok->strAt(3);
|
||||
if (*s == '\'')
|
||||
_errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok));
|
||||
_errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok->next()));
|
||||
|
||||
// char variable..
|
||||
unsigned int varid = tok->tokAt(2)->varId();
|
||||
unsigned int varid = tok->tokAt(3)->varId();
|
||||
if (varid > 0 && varid < 10000 && charVars[varid])
|
||||
_errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok));
|
||||
_errorLogger->reportErr(ErrorMessage::strPlusChar(_tokenizer, tok->next()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
|
||||
TEST_CASE(strPlusChar1); // "/usr" + '/'
|
||||
TEST_CASE(strPlusChar2); // "/usr" + ch
|
||||
TEST_CASE(strPlusChar3); // ok: path + "/sub" + '/'
|
||||
}
|
||||
|
||||
void check(const char code[])
|
||||
|
@ -201,6 +202,17 @@ private:
|
|||
ASSERT_EQUALS(std::string("[test.cpp:4]: Unusual pointer arithmetic\n"), errout.str());
|
||||
}
|
||||
|
||||
void strPlusChar3()
|
||||
{
|
||||
// Strange looking pointer arithmetic..
|
||||
strPlusChar("void foo()\n"
|
||||
"{\n"
|
||||
" std::string temp = \"/tmp\";\n"
|
||||
" std::string path = temp + '/' + \"sub\" + '/';\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestOther)
|
||||
|
|
Loading…
Reference in New Issue