Fixed #4183 (false positive with method named c_str())
This commit is contained in:
parent
fe8b6f0f95
commit
40719c56db
|
@ -1194,8 +1194,11 @@ void CheckStl::string_c_str()
|
|||
tok2 = tok->next()->link();
|
||||
else
|
||||
tok2 = tok2->previous();
|
||||
if (tok2 && Token::simpleMatch(tok2->tokAt(-4), ". c_str ( )"))
|
||||
string_c_strParam(tok, i->second);
|
||||
if (tok2 && Token::simpleMatch(tok2->tokAt(-4), ". c_str ( )")) {
|
||||
const Variable* var = symbolDatabase->getVariableFromVarId(tok2->tokAt(-5)->varId());
|
||||
if (var && Token::Match(var->typeStartToken(), "const| std :: string|wstring"))
|
||||
string_c_strParam(tok, i->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1864,6 +1864,15 @@ private:
|
|||
" return hello().c_str();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:11]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
|
||||
|
||||
// #4183 - using MyStringClass.c_str()
|
||||
check("void a(const std::string &str);\n"
|
||||
"\n"
|
||||
"void b() {\n"
|
||||
" MyStringClass s;\n"
|
||||
" a(s.c_str());\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void autoPointer() {
|
||||
|
|
Loading…
Reference in New Issue