]> granicus.if.org Git - python/commitdiff
Issue #16404: Add checks for return value of PyInt_FromLong() in
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 17 Dec 2013 13:09:45 +0000 (15:09 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 17 Dec 2013 13:09:45 +0000 (15:09 +0200)
sys.getwindowsversion() and ossaudiodev.setparameters().
Reported by Ned Batchelder.

Modules/ossaudiodev.c
Python/sysmodule.c

index edf1a0e7b7796d820af4fba93c9af24b2bce8a72..284cc610761900ca877f4c03d6e4997d7520f165 100644 (file)
@@ -490,7 +490,6 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
 {
     int wanted_fmt, wanted_channels, wanted_rate, strict=0;
     int fmt, channels, rate;
-    PyObject * rv;                    /* return tuple (fmt, channels, rate) */
 
     if (!PyArg_ParseTuple(args, "iii|i:setparameters",
                           &wanted_fmt, &wanted_channels, &wanted_rate,
@@ -532,13 +531,7 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
 
     /* 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, PyInt_FromLong(fmt));
-    PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
-    PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
-    return rv;
+    return Py_BuildValue("(iii)", fmt, channels, rate);
 }
 
 static int
index fa66eb4c419875c5909fc972de75aea79d7a30ab..2c364af0b7bebba37e832bd104e5cdd0d31bc750 100644 (file)
@@ -616,6 +616,10 @@ sys_getwindowsversion(PyObject *self)
     PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wSuiteMask));
     PyStructSequence_SET_ITEM(version, pos++, PyInt_FromLong(ver.wProductType));
 
+    if (PyErr_Occurred()) {
+        Py_DECREF(version);
+        return NULL;
+    }
     return version;
 }