Skip to content

Commit 2b861b6

Browse files
committed
Use isVoidPointerType() and state the checked signature
1 parent b18957f commit 2b861b6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,16 +1371,15 @@ void MallocChecker::checkIfFreeNameIndex(ProgramStateRef State,
13711371
C.addTransition(State);
13721372
}
13731373

1374-
bool isVoidStar(QualType T) {
1375-
return !T.isNull() && T->isPointerType() && T->getPointeeType()->isVoidType();
1376-
}
1377-
13781374
const Expr *getPlacementNewBufferArg(const CallExpr *CE,
13791375
const FunctionDecl *FD) {
1380-
if (CE->getNumArgs() == 1)
1376+
// Checking for signature:
1377+
// void* operator new ( std::size_t count, void* ptr );
1378+
// void* operator new[]( std::size_t count, void* ptr );
1379+
if (CE->getNumArgs() != 2)
13811380
return nullptr;
1382-
// Second argument of placement new must be void*
1383-
if (!isVoidStar(FD->getParamDecl(1)->getType()))
1381+
auto BuffType = FD->getParamDecl(1)->getType();
1382+
if (BuffType.isNull() || !BuffType->isVoidPointerType())
13841383
return nullptr;
13851384
return CE->getArg(1);
13861385
}

0 commit comments

Comments
 (0)