cfref_rdar6080742.c revision d427023c334fe03105d9359711a3df4d6f23b344
1// RUN: clang -analyze -checker-cfref -verify %s 2 3// This test case was reported in <rdar:problem/6080742>. 4// It tests path-sensitivity with respect to '!(cfstring != 0)' (negation of inequality). 5 6int printf(const char *restrict,...); 7typedef unsigned long UInt32; 8typedef signed long SInt32; 9typedef SInt32 OSStatus; 10typedef unsigned char Boolean; 11enum { noErr = 0}; 12typedef const void *CFTypeRef; 13typedef const struct __CFString *CFStringRef; 14typedef const struct __CFAllocator *CFAllocatorRef; 15extern void CFRelease(CFTypeRef cf); 16typedef UInt32 CFStringEncoding; 17enum { kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, 18 kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, 19 kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, 20 kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF, 21 kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, 22 kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, 23 kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100}; 24extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding); 25 26enum { memROZWarn = -99, memROZError = -99, memROZErr = -99, memFullErr = -108, 27 nilHandleErr = -109, memWZErr = -111, memPurErr = -112, memAdrErr = -110, 28 memAZErr = -113, memPCErr = -114, memBCErr = -115, memSCErr = -116, memLockedErr = -117}; 29 30#define DEBUG1 31 32void DebugStop(const char *format,...); 33void DebugTraceIf(unsigned int condition, const char *format,...); 34Boolean DebugDisplayOSStatusMsg(OSStatus status, const char *statusStr, const char *fileName, unsigned long lineNumber); 35 36#define Assert(condition)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); } 37#define AssertMsg(condition, message)if (!(condition)) { DebugStop("Assertion failure: %s (%s) [File: %s, Line: %lu]", #condition, message, __FILE__, __LINE__); } 38#define Require(condition)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); } 39#define RequireAction(condition, action)if (!(condition)) { DebugStop("Assertion failure: %s [File: %s, Line: %lu]", #condition, __FILE__, __LINE__); action } 40#define RequireActionSilent(condition, action)if (!(condition)) { action } 41#define AssertNoErr(err){ DebugDisplayOSStatusMsg((err), #err, __FILE__, __LINE__); } 42#define RequireNoErr(err, action){ if( DebugDisplayOSStatusMsg((err), #err, __FILE__, __LINE__) ) { action }} 43 44void DebugStop(const char *format,...); /* Not an abort function. */ 45 46int main(int argc, char *argv[]) { 47 CFStringRef cfString; 48 OSStatus status = noErr; 49 cfString = CFStringCreateWithCString(0, "hello", kCFStringEncodingUTF8); 50 RequireAction(cfString != 0, return memFullErr;) //no - warning 51 printf("cfstring %p\n", cfString); 52Exit: 53 CFRelease(cfString); 54 return 0; 55} 56