The analyzer is correct. Your code will gain access to garbage memory if _numberOfColumns is 0, thereby allocating 0 bytes for heights , making garbage heights[0] . The analyzer does not know what values _numberOfColumns values ββcan have, but you can say this with assert(_numberOfColumns>0) .
Take this program C, for example:
int main(int argc, const char * argv[]) { int n = argc-1; int *a = malloc(n*sizeof(int)); for (int i=0; i<n; i++) { a[i] = i; } int foo = a[0]; free(a); return foo; }
the size of a is determined by the number of arguments. If you have no arguments n == 0 . If you are sure that your program (or only this part of your program) will always assign something more from 0 to a , you can use the statement. Adding assert(n>0) will tell the analyzer exactly.
source share