[cfe-commits] r166002 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp test/Analysis/CFContainers-invalid.c
Jordan Rose
jordan_rose at apple.com
Mon Oct 15 17:47:28 PDT 2012
Author: jrose
Date: Mon Oct 15 19:47:25 2012
New Revision: 166002
URL: http://llvm.org/viewvc/llvm-project?rev=166002&view=rev
Log:
[analyzer] ObjCContainersASTChecker: minor cleanup and an extra test case.
Follow-up to r165838, which fixed a potential crash.
Added:
cfe/trunk/test/Analysis/CFContainers-invalid.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp?rev=166002&r1=166001&r2=166002&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersASTChecker.cpp Mon Oct 15 19:47:25 2012
@@ -31,8 +31,6 @@
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 @@
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 @@
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 @@
}
}
- 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;
Added: cfe/trunk/test/Analysis/CFContainers-invalid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/CFContainers-invalid.c?rev=166002&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/CFContainers-invalid.c (added)
+++ cfe/trunk/test/Analysis/CFContainers-invalid.c Mon Oct 15 19:47:25 2012
@@ -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);
+}
More information about the cfe-commits
mailing list