]> granicus.if.org Git - python/commitdiff
Issue #21639: Fix a division by zero in tracemalloc on calloc(0, 0). The
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 2 Jun 2014 19:40:22 +0000 (21:40 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 2 Jun 2014 19:40:22 +0000 (21:40 +0200)
regression was introduced recently with the introduction of the new "calloc"
functions (PyMem_RawCalloc, PyMem_Calloc, PyObject_Calloc).

Add also a unit test to check for the non-regression.

1  2 
Modules/_tracemalloc.c

index 429b209c021c394d5c665f3635b3e8d7a71c75c1,780e8eda82631fc08017fdfaa4b8660307dab761..1e454144de12293ff58932e0bd33bd886da4e8a3
@@@ -478,12 -481,7 +478,12 @@@ tracemalloc_alloc(int use_calloc, void 
      PyMemAllocator *alloc = (PyMemAllocator *)ctx;
      void *ptr;
  
-     assert(nelem <= PY_SIZE_MAX / elsize);
 -    ptr = alloc->malloc(alloc->ctx, size);
++    assert(elsize == 0 || nelem <= PY_SIZE_MAX / elsize);
 +
 +    if (use_calloc)
 +        ptr = alloc->calloc(alloc->ctx, nelem, elsize);
 +    else
 +        ptr = alloc->malloc(alloc->ctx, nelem * elsize);
      if (ptr == NULL)
          return NULL;