Skip to content

False positive in a function marked raising on negative result #158

Open
@dvarrazzo

Description

@dvarrazzo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions