aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis-Apple/CFString.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis-Apple/CFString.c')
-rw-r--r--test/Analysis-Apple/CFString.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/Analysis-Apple/CFString.c b/test/Analysis-Apple/CFString.c
new file mode 100644
index 0000000000..ebd9275e10
--- /dev/null
+++ b/test/Analysis-Apple/CFString.c
@@ -0,0 +1,30 @@
+// RUN: clang -checker-cfref -verify %s
+
+#include <CoreFoundation/CFString.h>
+#include <CoreFoundation/CFArray.h>
+
+void f1() {
+
+ // Create the array.
+ CFMutableArrayRef A = CFArrayCreateMutable(NULL, 10, &kCFTypeArrayCallBacks);
+
+ // Create a string.
+ CFStringRef s1 = CFStringCreateWithCString(NULL, "hello world",
+ kCFStringEncodingUTF8);
+
+ // Add the string to the array.
+ CFArrayAppendValue(A, s1);
+
+ // Decrement the reference count.
+ CFRelease(s1); // no-warning
+
+ // Get the string. We don't own it.
+ s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
+
+ // Release the array.
+ CFRelease(A); // no-warning
+
+ // Release the string. This is a bug.
+ CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}}
+}
+