From 640431c5698e29d67b9790d4df11959c46e02022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Mar 2014 17:38:07 +0200 Subject: [PATCH] Fixed #5611 (segfault when checking pcsc-cyberjack. either symboldatabase or checkMemset) --- lib/checkclass.cpp | 20 ++++++++++++++------ lib/checkclass.h | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3d124a812..04746676b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1008,10 +1008,13 @@ void CheckClass::checkMemset() type = t->classScope; } - if (type) - checkMemsetType(&(*scope), tok, type, false); + if (type) { + std::list 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 (")) { - checkMemsetType(&(*scope), tok->tokAt(2), tok->variable()->typeScope(), true); + std::list parsedTypes; + checkMemsetType(&(*scope), tok->tokAt(2), tok->variable()->typeScope(), true, parsedTypes); if (tok->variable()->typeScope()->numConstructors > 0 && _settings->isEnabled("warning")) 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 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 for (std::size_t i = 0; i < type->definedType->derivedFrom.size(); i++) { 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 @@ -1062,7 +1070,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco // check for known type else if (typeScope && typeScope != type) - checkMemsetType(start, tok, typeScope, allocation); + checkMemsetType(start, tok, typeScope, allocation, parsedTypes); } } } diff --git a/lib/checkclass.h b/lib/checkclass.h index 33e584d34..74f528b59 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -94,7 +94,7 @@ public: * Important: The checking doesn't work on simplified tokens list. */ 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 parsedTypes); /** @brief 'operator=' should return something and it should not be const. */ void operatorEq();