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

BUG: core: add missing error check after PyLong_AsSsize_t #8114

Merged
merged 1 commit into from
Oct 4, 2016

Conversation

pv
Copy link
Member

@pv pv commented Oct 3, 2016

Trivial bugfix. PyLong can overflow ssize_t, so need to check error.

@@ -3981,6 +3981,9 @@ array_shares_memory_impl(PyObject *args, PyObject *kwds, Py_ssize_t default_max_
}
else if (PyLong_Check(max_work_obj)) {
max_work = PyLong_AsSsize_t(max_work_obj);
if (PyErr_Occurred()) {
Copy link
Member

Choose a reason for hiding this comment

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

LGTM, two small comments (which I don't care much about)

  1. Could use PyNumber_Index here, which is a bit more general then the long check, but also forbids floats, etc.
  2. Could make it if ((max_work == -)1 && (PyErr_Occured())) { AFAIK.

Copy link
Member

Choose a reason for hiding this comment

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

(Or PyArray_PyIntAsIntp` which is however much the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Python 3 manual doesn't mention the -1 return value, so I didn't add that...

Copy link
Member

Choose a reason for hiding this comment

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

oh, really, did that change in python 3, seems odd?

@seberg
Copy link
Member

seberg commented Oct 4, 2016

Still wondering a bit about that -1, but it does not really matter here anyway. Thanks Pauli!

@seberg seberg merged commit 9914e60 into numpy:master Oct 4, 2016
@seberg
Copy link
Member

seberg commented Oct 4, 2016

Checked the code if you are curious, the -1 return value is used all over in cpython master, I think its a documentation oversight, but no matter.

@pv
Copy link
Member Author

pv commented Oct 4, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants