]> granicus.if.org Git - python/commitdiff
Fix spurious MemoryError introduced by PR #886. (#930)
authorT. Wouters <thomas@python.org>
Fri, 31 Mar 2017 17:10:19 +0000 (10:10 -0700)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2017 17:10:19 +0000 (10:10 -0700)
Fix MemoryError caused by moving around code in PR #886; nbytes was sometimes used unitinitalized (in non-debug builds, when use_calloc was false and elsize was 0).

Objects/obmalloc.c

index f284d9fc0a2c7937265dd8d03efe9f77051b62fe..32e7ecbe1e0436867cca5262abd3e12c8f72f23a 100644 (file)
@@ -1227,10 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
 
     _Py_AllocatedBlocks++;
 
-    if (nelem == 0 || elsize == 0)
-        goto redirect;
-
-    assert(nelem <= PY_SSIZE_T_MAX / elsize);
+    assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
     nbytes = nelem * elsize;
 
 #ifdef WITH_VALGRIND
@@ -1240,6 +1237,9 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
         goto redirect;
 #endif
 
+    if (nelem == 0 || elsize == 0)
+        goto redirect;
+
     if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
         LOCK();
         /*