Skip to content

Conversation

@tiran
Copy link
Member

@tiran tiran commented Mar 2, 2017

Coverity complains about three new potential NULL derefs. One is a false
positive but the two remaining look valid.

CID 1401656
CID 1401655

Signed-off-by: Christian Heimes [email protected]

@mention-bot
Copy link

@tiran, thanks for your PR! By analyzing the history of the files in this pull request, we identified @serhiy-storchaka, @amauryfa, @Haypo, @vadmium and @birkenfeld to be potential reviewers.

@serhiy-storchaka serhiy-storchaka self-requested a review March 2, 2017 22:08
@berkerpeksag
Copy link
Member

CID 1401656
CID 1401656

It looks like one of them should be CID 1401655.

Coverity complains about three new potential NULL derefs. One is a false
positive but the two remaining look valid.

CID 1401656
CID 1401655

Signed-off-by: Christian Heimes <[email protected]>
@tiran tiran force-pushed the bpo-28129-coverity branch from 69a1455 to 0efd813 Compare March 2, 2017 22:16
@serhiy-storchaka
Copy link
Member

At first glance both cases look false positive to me. Is there a reproducer?

}

dict = PyType_stgdict((PyObject *)type);
if (dict == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've started to put curly braces around one-liners: https://www.python.org/dev/peps/pep-0007/#code-lay-out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaaah, thanks for the confirmation @brettcannon ! I had a long discussion with @serhiy-storchaka about that ;-)

}

dict = PyType_stgdict((PyObject *)type);
if (dict == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaaah, thanks for the confirmation @brettcannon ! I had a long discussion with @serhiy-storchaka about that ;-)

@vstinner
Copy link
Member

vstinner commented Mar 3, 2017

LGTM, but please see @brettcannon comment on coding style.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked the code yet once and confirm that these changes are not needed. PyType_stgdict() never returns NULL in that cases.

Py_DECREF(result);
return NULL;
}
sw_dict = PyType_stgdict(swapped);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyType_stgdict() never returns NULL here since CreateSwappedType() just created a type with PyCStgDict.

return -1;
}

dict = PyType_stgdict((PyObject *)type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyType_stgdict() never returns NULL here since _init_pos_args() is called only for _ctypes.Structure and _ctypes.Union which creates types with PyCStgDict or recursively for their base classes after checking that PyType_stgdict() is not NULL.

@vstinner
Copy link
Member

If the code path cannot happen (false positive), can be fix the warning using an assertion?

Copy link
Member

@zhangyangyu zhangyangyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I scan the code and concur with Serhiy don't see the NULL code path.

@serhiy-storchaka
Copy link
Member

I think it is worth to add asserts. If NULL is happen here, this is our programming error.

@serhiy-storchaka
Copy link
Member

Sorry, pressed wrong button.

@tiran tiran closed this Sep 5, 2017
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

Successfully merging this pull request may close these issues.

9 participants