Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify %s
      2 
      3 typedef signed char BOOL;
      4 typedef long NSInteger;
      5 typedef unsigned long NSUInteger;
      6 @interface NSString @end
      7 @interface NSString (NSStringExtensionMethods)
      8 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
      9 @end
     10 
     11 @interface NSNumber
     12 + (NSNumber *)numberWithChar:(char)value;
     13 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
     14 + (NSNumber *)numberWithShort:(short)value;
     15 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
     16 + (NSNumber *)numberWithInt:(int)value;
     17 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
     18 + (NSNumber *)numberWithLong:(long)value;
     19 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
     20 + (NSNumber *)numberWithLongLong:(long long)value;
     21 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
     22 + (NSNumber *)numberWithFloat:(float)value;
     23 + (NSNumber *)numberWithDouble:(double)value;
     24 + (NSNumber *)numberWithBool:(BOOL)value;
     25 + (NSNumber *)numberWithInteger:(NSInteger)value ;
     26 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
     27 @end
     28 
     29 
     30 extern char *strdup(const char *str);
     31 
     32 id constant_string() {
     33     return @("boxed constant string.");
     34 }
     35 
     36 id dynamic_string() {
     37     return @(strdup("boxed dynamic string")); // expected-warning{{Potential memory leak}}
     38 }
     39 
     40 id const_char_pointer(int *x) {
     41   if (x)
     42     return @(3);
     43   return @(*x); // expected-warning {{Dereference of null pointer (loaded from variable 'x')}}
     44 }