]> granicus.if.org Git - python/commitdiff
Issue #18294: Fix uint_converter() in zlibmodule.c, fix the "> UINT_MAX" check
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Jan 2014 11:26:12 +0000 (12:26 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 3 Jan 2014 11:26:12 +0000 (12:26 +0100)
Modules/zlibmodule.c

index bf8c8e4d1212a604c699c6fa346912489b792ce6..28ed3cdca4832d5942a0a344ffc4a792761f249c 100644 (file)
@@ -329,11 +329,6 @@ uint_converter(PyObject *obj, void *ptr)
         uval = PyLong_AsUnsignedLong(obj);
         if (uval == (unsigned long)-1 && PyErr_Occurred())
             return 0;
-        if (uval > UINT_MAX) {
-            PyErr_SetString(PyExc_OverflowError,
-                            "Python int too large for C unsigned int");
-            return 0;
-        }
     }
     else {
         if (val < 0) {
@@ -344,6 +339,12 @@ uint_converter(PyObject *obj, void *ptr)
         uval = (unsigned long)val;
     }
 
+    if (uval > UINT_MAX) {
+        PyErr_SetString(PyExc_OverflowError,
+                        "Python int too large for C unsigned int");
+        return 0;
+    }
+
     *(unsigned int *)ptr = Py_SAFE_DOWNCAST(uval, unsigned long, unsigned int);
     return 1;
 }