diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-10-16 00:47:25 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-10-16 00:47:25 +0000 |
commit | bc9e5ffb0d0757238c071764e4bc1fc8a1521097 (patch) | |
tree | 22575e46d48b80ee1594e593343ea57e36ee532d | |
parent | 81765577dbf740c7cef1edfe59661c95408fa85b (diff) |
[analyzer] ObjCContainersASTChecker: minor cleanup and an extra test case.
Follow-up to r165838, which fixed a potential crash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166002 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp | 14 | ||||
-rw-r--r-- | test/Analysis/CFContainers-invalid.c | 19 |
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp index 9c0c3cd3b6..63a84805e7 100644 --- a/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp @@ -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; diff --git a/test/Analysis/CFContainers-invalid.c b/test/Analysis/CFContainers-invalid.c new file mode 100644 index 0000000000..939af06b76 --- /dev/null +++ b/test/Analysis/CFContainers-invalid.c @@ -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); +} |