Fixed #5611 (segfault when checking pcsc-cyberjack. either symboldatabase or checkMemset)
This commit is contained in:
parent
060f9035c9
commit
640431c569
|
@ -1008,10 +1008,13 @@ void CheckClass::checkMemset()
|
||||||
type = t->classScope;
|
type = t->classScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type)
|
if (type) {
|
||||||
checkMemsetType(&(*scope), tok, type, false);
|
std::list<const Scope *> parsedTypes;
|
||||||
|
checkMemsetType(&(*scope), tok, type, false, parsedTypes);
|
||||||
|
}
|
||||||
} else if (tok->variable() && tok->variable()->typeScope() && Token::Match(tok, "%var% = calloc|malloc|realloc|g_malloc|g_try_malloc|g_realloc|g_try_realloc (")) {
|
} else if (tok->variable() && tok->variable()->typeScope() && Token::Match(tok, "%var% = calloc|malloc|realloc|g_malloc|g_try_malloc|g_realloc|g_try_realloc (")) {
|
||||||
checkMemsetType(&(*scope), tok->tokAt(2), tok->variable()->typeScope(), true);
|
std::list<const Scope *> parsedTypes;
|
||||||
|
checkMemsetType(&(*scope), tok->tokAt(2), tok->variable()->typeScope(), true, parsedTypes);
|
||||||
|
|
||||||
if (tok->variable()->typeScope()->numConstructors > 0 && _settings->isEnabled("warning"))
|
if (tok->variable()->typeScope()->numConstructors > 0 && _settings->isEnabled("warning"))
|
||||||
mallocOnClassWarning(tok, tok->strAt(2), tok->variable()->typeScope()->classDef);
|
mallocOnClassWarning(tok, tok->strAt(2), tok->variable()->typeScope()->classDef);
|
||||||
|
@ -1020,12 +1023,17 @@ void CheckClass::checkMemset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type, bool allocation)
|
void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type, bool allocation, std::list<const Scope *> parsedTypes)
|
||||||
{
|
{
|
||||||
|
// If type has been checked there is no need to check it again
|
||||||
|
if (std::find(parsedTypes.begin(), parsedTypes.end(), type) != parsedTypes.end())
|
||||||
|
return;
|
||||||
|
parsedTypes.push_back(type);
|
||||||
|
|
||||||
// recursively check all parent classes
|
// recursively check all parent classes
|
||||||
for (std::size_t i = 0; i < type->definedType->derivedFrom.size(); i++) {
|
for (std::size_t i = 0; i < type->definedType->derivedFrom.size(); i++) {
|
||||||
if (type->definedType->derivedFrom[i].type && type->definedType->derivedFrom[i].type->classScope)
|
if (type->definedType->derivedFrom[i].type && type->definedType->derivedFrom[i].type->classScope)
|
||||||
checkMemsetType(start, tok, type->definedType->derivedFrom[i].type->classScope, allocation);
|
checkMemsetType(start, tok, type->definedType->derivedFrom[i].type->classScope, allocation, parsedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn if type is a class that contains any virtual functions
|
// Warn if type is a class that contains any virtual functions
|
||||||
|
@ -1062,7 +1070,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
|
||||||
|
|
||||||
// check for known type
|
// check for known type
|
||||||
else if (typeScope && typeScope != type)
|
else if (typeScope && typeScope != type)
|
||||||
checkMemsetType(start, tok, typeScope, allocation);
|
checkMemsetType(start, tok, typeScope, allocation, parsedTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
* Important: The checking doesn't work on simplified tokens list.
|
* Important: The checking doesn't work on simplified tokens list.
|
||||||
*/
|
*/
|
||||||
void checkMemset();
|
void checkMemset();
|
||||||
void checkMemsetType(const Scope *start, const Token *tok, const Scope *type, bool allocation);
|
void checkMemsetType(const Scope *start, const Token *tok, const Scope *type, bool allocation, std::list<const Scope *> parsedTypes);
|
||||||
|
|
||||||
/** @brief 'operator=' should return something and it should not be const. */
|
/** @brief 'operator=' should return something and it should not be const. */
|
||||||
void operatorEq();
|
void operatorEq();
|
||||||
|
|
Loading…
Reference in New Issue