blob: 9f59ebf6ac9eaa83a8c21eaa2a6fa2bafd951a8c [file] [log] [blame]
Ted Kremenek7662af42008-06-16 19:35:31 +00001// RUN: clang -checker-cfref -verify %s
2
3//===----------------------------------------------------------------------===//
4// The following code is reduced using delta-debugging from
5// CoreFoundation.h (Mac OS X).
6//
7// It includes the basic definitions for the test cases below.
8// Not directly including CoreFoundation.h directly makes this test case
Ted Kremenekdfc996c2008-06-16 19:51:41 +00009// both svelte and portable to non-Mac platforms.
Ted Kremenek7662af42008-06-16 19:35:31 +000010//===----------------------------------------------------------------------===//
11
12typedef signed long CFIndex;
13typedef const struct __CFString * CFStringRef;
14typedef struct {} CFArrayCallBacks;
15extern const CFArrayCallBacks kCFTypeArrayCallBacks;
16typedef const struct __CFArray * CFArrayRef;
17typedef struct __CFArray * CFMutableArrayRef;
18extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
19enum { kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 };
20
21//===----------------------------------------------------------------------===//
22// Test cases.
23//===----------------------------------------------------------------------===//
24
25void f1() {
26
27 // Create the array.
28 CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
29
30 // Create a string.
31 CFStringRef s1 = CFStringCreateWithCString(0, "hello world",
32 kCFStringEncodingUTF8);
33
34 // Add the string to the array.
35 CFArrayAppendValue(A, s1);
36
37 // Decrement the reference count.
38 CFRelease(s1); // no-warning
39
40 // Get the string. We don't own it.
41 s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
42
43 // Release the array.
44 CFRelease(A); // no-warning
45
46 // Release the string. This is a bug.
47 CFRelease(s1); // expected-warning{{Incorrect decrement of the reference count}}
48}
49