Merge pull request #650 from simartin/memset_indirections_fix
Fix CheckClass::checkMemset for arrays of pointers.
This commit is contained in:
commit
83c4afa694
|
@ -1010,28 +1010,30 @@ void CheckClass::checkMemset()
|
||||||
else if (Token::simpleMatch(arg3, "sizeof ( * this ) )") || Token::simpleMatch(arg1, "this ,")) {
|
else if (Token::simpleMatch(arg3, "sizeof ( * this ) )") || Token::simpleMatch(arg1, "this ,")) {
|
||||||
type = findFunctionOf(arg3->scope());
|
type = findFunctionOf(arg3->scope());
|
||||||
} else if (Token::Match(arg1, "&|*|%var%")) {
|
} else if (Token::Match(arg1, "&|*|%var%")) {
|
||||||
int derefs = 1;
|
int numIndirToVariableType = 0; // Offset to the actual type in terms of dereference/addressof
|
||||||
for (;; arg1 = arg1->next()) {
|
for (;; arg1 = arg1->next()) {
|
||||||
if (arg1->str() == "&")
|
if (arg1->str() == "&")
|
||||||
derefs--;
|
++numIndirToVariableType;
|
||||||
else if (arg1->str() == "*")
|
else if (arg1->str() == "*")
|
||||||
derefs++;
|
--numIndirToVariableType;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Variable *var = arg1->variable();
|
const Variable *var = arg1->variable();
|
||||||
if (var && arg1->strAt(1) == ",") {
|
if (var && arg1->strAt(1) == ",") {
|
||||||
if (var->isPointer()) {
|
if (var->isArrayOrPointer()) {
|
||||||
derefs--;
|
const Token *endTok = var->typeEndToken();
|
||||||
if (var->typeEndToken() && Token::simpleMatch(var->typeEndToken()->previous(), "* *")) // Check if it's a pointer to pointer
|
while (endTok && Token::simpleMatch(endTok, "*")) {
|
||||||
derefs--;
|
--numIndirToVariableType;
|
||||||
|
endTok = endTok->previous();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var->isArray())
|
if (var->isArray())
|
||||||
derefs -= (int)var->dimensions().size();
|
numIndirToVariableType += (int)var->dimensions().size();
|
||||||
|
|
||||||
if (derefs == 0)
|
if (numIndirToVariableType == 1)
|
||||||
type = var->typeScope();
|
type = var->typeScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2581,10 +2581,7 @@ private:
|
||||||
" memset(c2, 0, 10);\n"
|
" memset(c2, 0, 10);\n"
|
||||||
" memset(c3, 0, 10);\n"
|
" memset(c3, 0, 10);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||||
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
|
||||||
"[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
|
||||||
"[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memsetOnStdPodType() { // Ticket #5901
|
void memsetOnStdPodType() { // Ticket #5901
|
||||||
|
|
Loading…
Reference in New Issue