1. ob_refcnt of '*item' is 1 too high

    Report

    1
    PyObject *
    make_a_list_of_random_ints_badly(PyObject *self,
    PyObject *args)
    {
    PyObject *list, *item;
    long count, i;
    if (!PyArg_ParseTuple(args, "i", &count)) {
    return NULL;
    }
    list = PyList_New(0);
    for (i = 0; i < count; i++) {
    item = PyLong_FromLong(random());
    PyList_Append(list, item);
    }
    return list;
    }
    1. when PyArg_ParseTuple() succeeds

      taking False path

    2. when PyList_New() succeeds

    3. when considering range: 1 <= count.0 <= 0x7fffffff

      taking True path

    4. when PyLong_FromLong() succeeds

    5. when PyList_Append() succeeds

    6. when considering count.0 == (int)1 from libcpychecker/html/test/example1/bug.c:10

      taking False path

    7. PyLongObject allocated at: item = PyLong_FromLong(random());

    8. was expecting final ob_refcnt to be N + 1 (for some unknown N)

      due to object being referenced by: PyListObject.ob_item[0]

      but final ob_refcnt is N + 2

      found 1 similar trace(s) to this

  2. calling PyList_Append with NULL as argument 1 (list) at libcpychecker/html/test/example1/bug.c:18

    Report

    2
    PyObject *
    make_a_list_of_random_ints_badly(PyObject *self,
    PyObject *args)
    {
    PyObject *list, *item;
    long count, i;
    if (!PyArg_ParseTuple(args, "i", &count)) {
    return NULL;
    }
    list = PyList_New(0);
    for (i = 0; i < count; i++) {
    item = PyLong_FromLong(random());
    PyList_Append(list, item);
    }
    return list;
    }
    1. when PyArg_ParseTuple() succeeds

      taking False path

    2. when PyList_New() fails

    3. when considering range: 1 <= count.0 <= 0x7fffffff

      taking True path

    4. when PyLong_FromLong() succeeds

    5. PyList_Append() invokes Py_TYPE() on the pointer via the PyList_Check() macro, thus accessing (NULL)->ob_type

      found 1 similar trace(s) to this