forked from OSchip/llvm-project
[analyzer] ObjCContainersASTChecker: minor cleanup and an extra test case.
Follow-up to r165838, which fixed a potential crash. llvm-svn: 166002
This commit is contained in:
parent
d9d4be0d57
commit
968a1b58fa
|
@ -31,8 +31,6 @@ class WalkAST : public StmtVisitor<WalkAST> {
|
|||
ASTContext &ASTC;
|
||||
uint64_t PtrWidth;
|
||||
|
||||
static const unsigned InvalidArgIndex = UINT_MAX;
|
||||
|
||||
/// Check if the type has pointer size (very conservative).
|
||||
inline bool isPointerSize(const Type *T) {
|
||||
if (!T)
|
||||
|
@ -102,7 +100,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
|
|||
return;
|
||||
|
||||
const Expr *Arg = 0;
|
||||
unsigned ArgNum = InvalidArgIndex;
|
||||
unsigned ArgNum;
|
||||
|
||||
if (Name.equals("CFArrayCreate") || Name.equals("CFSetCreate")) {
|
||||
if (CE->getNumArgs() != 4)
|
||||
|
@ -111,9 +109,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
|
|||
Arg = CE->getArg(ArgNum)->IgnoreParenCasts();
|
||||
if (hasPointerToPointerSizedType(Arg))
|
||||
return;
|
||||
}
|
||||
|
||||
if (Arg == 0 && Name.equals("CFDictionaryCreate")) {
|
||||
} else if (Name.equals("CFDictionaryCreate")) {
|
||||
if (CE->getNumArgs() != 6)
|
||||
return;
|
||||
// Check first argument.
|
||||
|
@ -129,13 +125,11 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
|
|||
}
|
||||
}
|
||||
|
||||
if (ArgNum != InvalidArgIndex) {
|
||||
if (Arg) {
|
||||
assert(ArgNum == 1 || ArgNum == 2);
|
||||
assert(Arg);
|
||||
|
||||
SmallString<256> BufName;
|
||||
SmallString<64> BufName;
|
||||
llvm::raw_svector_ostream OsName(BufName);
|
||||
assert(ArgNum == 1 || ArgNum == 2);
|
||||
OsName << " Invalid use of '" << Name << "'" ;
|
||||
|
||||
SmallString<256> Buf;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// RUN: %clang_cc1 -analyze -analyzer-checker=osx.coreFoundation.containers.PointerSizedValues -triple x86_64-apple-darwin -verify %s
|
||||
|
||||
typedef const struct __CFAllocator * CFAllocatorRef;
|
||||
typedef const struct __CFArray * CFArrayRef;
|
||||
typedef const struct __CFDictionary * CFDictionaryRef;
|
||||
typedef const struct __CFSet * CFSetRef;
|
||||
|
||||
extern const CFAllocatorRef kCFAllocatorDefault;
|
||||
|
||||
// Unexpected declarations for these:
|
||||
CFArrayRef CFArrayCreate(CFAllocatorRef);
|
||||
CFDictionaryRef CFDictionaryCreate(CFAllocatorRef);
|
||||
CFSetRef CFSetCreate(CFAllocatorRef);
|
||||
|
||||
void testNoCrash() {
|
||||
(void)CFArrayCreate(kCFAllocatorDefault);
|
||||
(void)CFDictionaryCreate(kCFAllocatorDefault);
|
||||
(void)CFSetCreate(kCFAllocatorDefault);
|
||||
}
|
Loading…
Reference in New Issue