Xcode Analyzer produces wrong warning: "Function call argument is an uninitialized value"

Originator:s.pankevich
Number:rdar://21383256 Date Originated:15-Jun-2015 07:24 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3.2 (6D2105)
Classification:Bug Reproducible:Always
 
Summary:

The following code produces: "Function call argument is an uninitialized value" warning while the code is written correctly.

#import <Foundation/Foundation.h>

int **Grid2DCreateRaw(NSUInteger gridSize) {
    if (gridSize == 0) {
        return NULL;
    }

    int **grid = malloc((gridSize + 2) * sizeof(int *));

    for (NSUInteger col = 0; col < (gridSize + 2); col++) {
        grid[col] = malloc((gridSize + 2) * sizeof(int));
    }

    memset(grid[0], 0, (gridSize + 2) * sizeof(int));

    return grid;
}

void Grid2DFree(int **grid, NSUInteger gridSize) {
    for (NSUInteger col = 0; col < (gridSize + 2); col++) {
        free(grid[col]);
    }
    free(grid);
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSUInteger size = (NSUInteger)1.0; // analyzer warning appears

        // NSUInteger size = (NSUInteger)1; // analyzer warning does not appear

        int **grid = Grid2DCreateRaw(size);

        if (grid == NULL) {
            return 0;
        }

        Grid2DFree(grid, size);
    }
    
    return 0;
}

Steps to Reproduce:

1. Create new project from template: "Command Line Tool", paste the code from Description into its main.m file.
2. Run Analyze
3. See the warning.

Expected Results:

This warning should not appear

Actual Results:

Warning appears

Version:

Version 6.3.2 (6D2105)

Notes:

I created project which demonstrates this: https://github.com/stanislaw/Reports/tree/20150615-xcode-analyzer-bug

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!