Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store=region -verify -Wno-objc-root-class -fblocks %s
      2 #include "Inputs/system-header-simulator-objc.h"
      3 
      4 @class NSString;
      5 typedef __typeof(sizeof(int)) size_t;
      6 void *malloc(size_t);
      7 void free(void *);
      8 
      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 {
     14     char str_c;
     15 };
     16 @end
     17 
     18 void rdar10579586(char x);
     19 
     20 @implementation RDar10579586
     21 + (NSString *)foobar
     22 {
     23     struct rdar0579586_str *buffer = ((void*)0);
     24     NSString *error = ((void*)0);
     25 
     26     if ((buffer = malloc(sizeof(struct rdar0579586_str))) == ((void*)0))
     27         error = @"buffer allocation failure";
     28 
     29     if (error != ((void*)0))
     30         return error;
     31 
     32     rdar10579586(buffer->str_c); // expected-warning {{Function call argument is an uninitialized value}}
     33     free(buffer);
     34     return ((void*)0);
     35 }
     36 @end
     37 
     38