diff options
author | Sergio Martins <smartins@kde.org> | 2018-09-23 15:11:00 +0100 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2018-09-23 15:11:00 +0100 |
commit | 5b3a3464a2e0315dc452cc8574c4945afe2d8bf3 (patch) | |
tree | 5b3b72e51184cef47dcd76bedd0bc5ba784dec44 | |
parent | e644c4af0c3d6748bc5e90f1e222907bd359bd7e (diff) |
Fix crash in old-style-connect fixits
BUG: 388925
-rw-r--r-- | src/checks/level2/old-style-connect.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/checks/level2/old-style-connect.cpp b/src/checks/level2/old-style-connect.cpp index ebc4acca..991939b3 100644 --- a/src/checks/level2/old-style-connect.cpp +++ b/src/checks/level2/old-style-connect.cpp @@ -43,6 +43,27 @@ using namespace clang; using namespace std; +namespace clazy { +// Copied from Clang's Expr.cpp and added "|| !DerivedType->isRecordType()" to avoid a crash +const CXXRecordDecl *getBestDynamicClassType(Expr *expr) +{ + if (!expr) + return nullptr; + + const Expr *E = expr->getBestDynamicClassTypeExpr(); + QualType DerivedType = E->getType(); + if (const PointerType *PTy = DerivedType->getAs<PointerType>()) + DerivedType = PTy->getPointeeType(); + + if (DerivedType->isDependentType() || !DerivedType->isRecordType()) + return nullptr; + + const RecordType *Ty = DerivedType->castAs<RecordType>(); + Decl *D = Ty->getDecl(); + return cast<CXXRecordDecl>(D); +} +} + enum ConnectFlag { ConnectFlag_None = 0, // Not a disconnect or connect ConnectFlag_Connect = 1, // It's a connect @@ -437,7 +458,7 @@ vector<FixItHint> OldStyleConnect::fixits(int classification, CallExpr *call) lastRecordDecl = nullptr; } else { Expr *expr = arg; - const auto record = expr ? expr->getBestDynamicClassType() : nullptr; + const auto record = clazy::getBestDynamicClassType(expr); if (record) { lastRecordDecl = record; if (isQPointer(expr)) { |