Menu

False positive: [uninitvar]

Fan Zhang
2022-08-04
2022-08-04
  • Fan Zhang

    Fan Zhang - 2022-08-04
    #include <stdio.h>
    
    int return_false();
    
    int main()
    {
        int array[10];
        int idx = 0;
        if(return_false())
        {
            array[idx++] = 1;
        }
        for(int i = 0; i < idx; i++)
        {
            printf("%i\n", array[i]);
        }
        return 0;
    }
    

    Cppcheck outputs:

    Checking test.c ...
    test.c:15:24: error: Uninitialized variable: array [uninitvar]
            printf("%i\n", array[i]);
                           ^
    test.c:9:20: note: Assuming condition is false
        if(return_false())
                       ^
    test.c:15:24: note: Uninitialized variable: array
            printf("%i\n", array[i]);
                           ^
    
     
  • CHR

    CHR - 2022-08-04
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.