Fixed #4460: Ensure that memset/memcpy is called on a pointer to a class instance.
This commit is contained in:
parent
4c73c29cdd
commit
f5ebbff0a3
|
@ -847,8 +847,8 @@ void CheckClass::noMemset()
|
|||
else if (Token::Match(arg1, "&| %var% ,")) {
|
||||
unsigned int varid = arg1->str() == "&" ? arg1->next()->varId() : arg1->varId();
|
||||
const Variable *var = symbolDatabase->getVariableFromVarId(varid);
|
||||
if (var && (var->typeStartToken() == var->typeEndToken() ||
|
||||
Token::Match(var->typeStartToken(), "%type% :: %type%")))
|
||||
if (var && (var->typeStartToken() == var->typeEndToken() || Token::Match(var->typeStartToken(), "%type% :: %type%"))
|
||||
&& (arg1->str() == "&" || var->isPointer() || var->isArray()))
|
||||
typeTok = var->typeEndToken();
|
||||
}
|
||||
|
||||
|
|
|
@ -2282,6 +2282,16 @@ private:
|
|||
" memset(&a, 0, sizeof(A));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'.\n", errout.str());
|
||||
|
||||
checkNoMemset("struct A {\n"
|
||||
" std::vector<int *> buf;\n"
|
||||
" operator int*() {return &buf[0];}\n"
|
||||
"};\n"
|
||||
"void f() {\n"
|
||||
" A a;\n"
|
||||
" memset(a, 0, 100);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str()); // #4460
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue