2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify -Wno-objc-root-class -fblocks %s
|
2012-09-12 09:11:10 +08:00
|
|
|
#include "Inputs/system-header-simulator-objc.h"
|
2012-02-28 08:56:05 +08:00
|
|
|
|
|
|
|
@class NSString;
|
|
|
|
typedef __typeof(sizeof(int)) size_t;
|
|
|
|
void *malloc(size_t);
|
|
|
|
void free(void *);
|
|
|
|
|
|
|
|
// RDar10579586 - Test use of malloc() with Objective-C string literal as a
|
|
|
|
// test condition. Not really a malloc() issue, but this also exercises
|
|
|
|
// the check that malloc() returns uninitialized memory.
|
|
|
|
@interface RDar10579586
|
|
|
|
struct rdar0579586_str {
|
|
|
|
char str_c;
|
|
|
|
};
|
|
|
|
@end
|
|
|
|
|
|
|
|
void rdar10579586(char x);
|
|
|
|
|
|
|
|
@implementation RDar10579586
|
|
|
|
+ (NSString *)foobar
|
|
|
|
{
|
|
|
|
struct rdar0579586_str *buffer = ((void*)0);
|
|
|
|
NSString *error = ((void*)0);
|
|
|
|
|
|
|
|
if ((buffer = malloc(sizeof(struct rdar0579586_str))) == ((void*)0))
|
|
|
|
error = @"buffer allocation failure";
|
|
|
|
|
|
|
|
if (error != ((void*)0))
|
|
|
|
return error;
|
|
|
|
|
2017-03-08 23:22:24 +08:00
|
|
|
rdar10579586(buffer->str_c); // expected-warning {{1st function call argument is an uninitialized value}}
|
2012-02-28 08:56:05 +08:00
|
|
|
free(buffer);
|
|
|
|
return ((void*)0);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2013-06-01 07:47:32 +08:00
|
|
|
@interface MyArray : NSObject {
|
2013-06-01 06:39:13 +08:00
|
|
|
id * objects;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2013-06-01 07:47:32 +08:00
|
|
|
void _ArrayCreate() {
|
|
|
|
MyArray *array = (MyArray *)malloc(12);
|
2013-06-01 06:39:13 +08:00
|
|
|
array = [array init];
|
|
|
|
free(array); // no-warning
|
2013-06-01 07:47:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void testNSDataTruePositiveLeak() {
|
|
|
|
char *b = (char *)malloc(12);
|
|
|
|
NSData *d = [[NSData alloc] initWithBytes: b length: 12]; // expected-warning {{Potential leak of memory pointed to by 'b'}}
|
2014-01-08 05:39:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
id wrapInNSValue() {
|
|
|
|
void *buffer = malloc(4);
|
|
|
|
return [NSValue valueWithPointer:buffer]; // no-warning
|
2013-06-01 06:39:13 +08:00
|
|
|
}
|