gcc-python-plugin icon indicating copy to clipboard operation
gcc-python-plugin copied to clipboard

False positive in a function marked raising on negative result

Open dvarrazzo opened this issue 6 years ago • 0 comments

Found a false positive analysing this function:

A more synthetic case is:

RAISES_NEG static int
test_cpychecker(PyObject *pyval)
{
    int rv = -1;
    long val;

    if (PyInt_Check(pyval)) {
        val = PyInt_AsLong(pyval);
        if (val == -1 && PyErr_Occurred()) { goto exit; }
        if (val < 1 || val > 4) {
            PyErr_SetString(PyExc_ValueError,
                "isolation_level must be between 1 and 4");
            goto exit;
        }

        rv = val;

        /* Work around cpychecker false positive */
        /* if (rv < 0) { */
        /*     PyErr_SetString(PyExc_ValueError, */
        /*         "isolation_level must be between 1 and 4"); */
        /*     goto exit; */
        /* } */
    }

    else {
        rv = 1;
    }

exit:
    return rv;
}

where the case that 1 <= val <= 4 is not transferred to rv, so it seems a negative number can be returned with no exception, resulting in the following trace.

image

Enabling the commented block removes the false positive. I tried to add a test to the plugin test suite but no success.

dvarrazzo avatar Dec 28 '18 16:12 dvarrazzo