1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -verify -Wno-objc-root-class -fblocks %s
2 #include "Inputs/system-header-simulator-objc.h"
5 typedef __typeof(sizeof(int)) size_t;
9 // RDar10579586 - Test use of malloc() with Objective-C string literal as a
10 // test condition. Not really a malloc() issue, but this also exercises
11 // the check that malloc() returns uninitialized memory.
12 @interface RDar10579586
13 struct rdar0579586_str {
18 void rdar10579586(char x);
20 @implementation RDar10579586
23 struct rdar0579586_str *buffer = ((void*)0);
24 NSString *error = ((void*)0);
26 if ((buffer = malloc(sizeof(struct rdar0579586_str))) == ((void*)0))
27 error = @"buffer allocation failure";
29 if (error != ((void*)0))
32 rdar10579586(buffer->str_c); // expected-warning {{1st function call argument is an uninitialized value}}
38 @interface MyArray : NSObject {
43 void _ArrayCreate(void) {
44 MyArray *array = (MyArray *)malloc(12);
46 free(array); // no-warning
49 void testNSDataTruePositiveLeak(void) {
50 char *b = (char *)malloc(12);
51 NSData *d = [[NSData alloc] initWithBytes: b length: 12]; // expected-warning {{Potential leak of memory pointed to by 'b'}}
54 id wrapInNSValue(void) {
55 void *buffer = malloc(4);
56 return [NSValue valueWithPointer:buffer]; // no-warning