[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-12-17 Thread Roundup Robot

Roundup Robot added the comment:

New changeset debdfa44f020 by Serhiy Storchaka in branch '2.7':
Issue #16404: Add checks for return value of PyInt_FromLong() in
http://hg.python.org/cpython/rev/debdfa44f020

New changeset 928c0acf7c09 by Serhiy Storchaka in branch '3.3':
Issue #16404: Add checks for return value of PyLong_FromLong() in
http://hg.python.org/cpython/rev/928c0acf7c09

New changeset d489394a73de by Serhiy Storchaka in branch 'default':
Issue #16404: Add checks for return value of PyLong_FromLong() in
http://hg.python.org/cpython/rev/d489394a73de

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-12-17 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - committed/rejected

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-12-17 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-12-02 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-11-30 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch. arraymodule.c is already fixed. Instead I found other bug in 
sysmodule.c. I'm not sure about extending.rst, PyLong_FromLong(0L) should never 
fail if NSMALLNEGINTS + NSMALLPOSINTS  0.

--
keywords: +patch
stage: needs patch - patch review
versions:  -Python 3.2
Added file: http://bugs.python.org/file32908/issue16404.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-11-30 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Removed file: http://bugs.python.org/file32908/issue16404.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-11-30 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
components:  -Documentation, Interpreter Core
Added file: http://bugs.python.org/file32910/issue16404.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2013-01-07 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
assignee: docs@python - serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2012-11-15 Thread Andrew Svetlov

Changes by Andrew Svetlov andrew.svet...@gmail.com:


--
nosy: +asvetlov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2012-11-05 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2012-11-04 Thread Ned Batchelder

New submission from Ned Batchelder:

Examining the CPython sources, there are a number of places where 
PyLong_FromLong is used without checking its return value. In places where it 
is done correctly, PyErr_Occurred is often used to avoid having to check every 
call.

Here are places where it isn't done properly.  I can make patches if desired, 
though I can't build and test on Windows.  This code is from CPython tip, but 
the same issues exist in the 2.7 branch.

In Modules/arraymodule.c:

static PyObject *
array_buffer_info(arrayobject *self, PyObject *unused)
{
PyObject* retval = NULL;
retval = PyTuple_New(2);
if (!retval)
return NULL;

PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self-ob_item));
PyTuple_SET_ITEM(retval, 1, PyLong_FromLong((long)(Py_SIZE(self;

return retval;
}

In Modules/ossaudiodev.c

/* Construct the return value: a (fmt, channels, rate) tuple that
   tells what the audio hardware was actually set to. */
rv = PyTuple_New(3);
if (rv == NULL)
return NULL;
PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(fmt));
PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(channels));
PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(rate));
return rv;

These 7 lines could be replaced simply with:

return Py_BuildValue((iii), fmt, channels, rate);


In Python/sysmodule.c, where the PyUnicode_FromString is far more worrisome:

static PyObject *
sys_getwindowsversion(PyObject *self)
{
PyObject *version;
int pos = 0;
OSVERSIONINFOEX ver;
ver.dwOSVersionInfoSize = sizeof(ver);
if (!GetVersionEx((OSVERSIONINFO*) ver))
return PyErr_SetFromWindowsErr(0);

version = PyStructSequence_New(WindowsVersionType);
if (version == NULL)
return NULL;

PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.dwMajorVersion));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.dwMinorVersion));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.dwBuildNumber));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.dwPlatformId));
PyStructSequence_SET_ITEM(version, pos++, 
PyUnicode_FromString(ver.szCSDVersion));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.wServicePackMajor));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.wServicePackMinor));
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
PyStructSequence_SET_ITEM(version, pos++, 
PyLong_FromLong(ver.wProductType));

return version;
}

In Doc/extending/extending.rst, as an example of a correct function!:

   void
   no_bug(PyObject *list)
   {
   PyObject *item = PyList_GetItem(list, 0);

   Py_INCREF(item);
   PyList_SetItem(list, 1, PyLong_FromLong(0L));
   PyObject_Print(item, stdout, 0);
   Py_DECREF(item);
   }

--
messages: 174809
nosy: nedbat
priority: normal
severity: normal
status: open
title: Uses of PyLong_FromLong that don't check for errors
versions: Python 2.7, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16404] Uses of PyLong_FromLong that don't check for errors

2012-11-04 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

See also issue15989.

--
assignee:  - docs@python
components: +Documentation, Extension Modules, Interpreter Core
nosy: +docs@python, mark.dickinson, serhiy.storchaka
stage:  - needs patch
type:  - behavior
versions: +Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16404
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com