[cfe-dev] [analyzer] RFC, garbage value => out of bounds

Daniel Marjamäki via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 14 01:44:42 PDT 2016


Hello!

I would like to change the analyzer so the a[i] value is not undefined when i is out of bounds.. to improve the Clang warnings.

Code example:

    void dostuff(int);

    void f(int nr) {
        int a[2] = {1,1};
        for (int i = 0; i < nr; i++)
            dostuff(a[i]);
    }


Output from Clang analyzer:

    /home/danielm/ossa/uninit.c:7:5: warning: Function call argument is an uninitialized value
        dostuff(a[i]);
        ^~~~~~~~~~~~~

The array a is fully initialized. So imho the message is a FP.

It is better to write "array index out of bounds". Like this:

    /home/danielm/ossa/uninit.c:7:13: warning: Access out-of-bound array element (buffer overflow)
        dostuff(a[i]);
                ^~~~

So.. if I change the analyzer the warning will not be shown unless the array-index check is enabled.

Do you have opinions?

Best regards,
Daniel Marjamäki

..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden

Mobile:                 +46 (0)709 12 42 62
E-mail:                 Daniel.Marjamaki at evidente.se

www.evidente.se


More information about the cfe-dev mailing list