Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dvarrazzo opened this issue Dec 28, 2018 · 0 comments
Open

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

dvarrazzo opened this issue Dec 28, 2018 · 0 comments

Comments

@dvarrazzo
Copy link
Contributor

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 dvarrazzo changed the title False positive in a function marked False positive in a function marked raising on negative result Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant