Ted Kremenek | 7662af4 | 2008-06-16 19:35:31 +0000 | [diff] [blame] | 1 | // 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 Kremenek | dfc996c | 2008-06-16 19:51:41 +0000 | [diff] [blame^] | 9 | // both svelte and portable to non-Mac platforms. |
Ted Kremenek | 7662af4 | 2008-06-16 19:35:31 +0000 | [diff] [blame] | 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | typedef signed long CFIndex; |
| 13 | typedef const struct __CFString * CFStringRef; |
| 14 | typedef struct {} CFArrayCallBacks; |
| 15 | extern const CFArrayCallBacks kCFTypeArrayCallBacks; |
| 16 | typedef const struct __CFArray * CFArrayRef; |
| 17 | typedef struct __CFArray * CFMutableArrayRef; |
| 18 | extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); |
| 19 | enum { 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 | |
| 25 | void 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 | |