summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2023-02-21 12:08:45 +0100
committerSebastian Berg <sebastianb@nvidia.com>2023-02-21 12:08:45 +0100
commit9a7f46a8d7abbd68e22c471d80cf00774e906967 (patch)
treea018a095cd255806410e2730e36c39f963e241e1 /numpy
parentb657a75ca651368b2d29c221287046333c3f7580 (diff)
downloadnumpy-9a7f46a8d7abbd68e22c471d80cf00774e906967.tar.gz
MAINT: Ensure malloc(0) is not called in pocketfft.c
Diffstat (limited to 'numpy')
-rw-r--r--numpy/fft/_pocketfft.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/numpy/fft/_pocketfft.c b/numpy/fft/_pocketfft.c
index 86de57bd3..d7090cd61 100644
--- a/numpy/fft/_pocketfft.c
+++ b/numpy/fft/_pocketfft.c
@@ -23,7 +23,7 @@
#include <stdlib.h>
#define RALLOC(type,num) \
- ((type *)malloc((num)*sizeof(type)))
+ (assert(num != 0), ((type *)malloc((num)*sizeof(type))))
#define DEALLOC(ptr) \
do { free(ptr); (ptr)=NULL; } while(0)
@@ -1056,8 +1056,10 @@ static cfftp_plan make_cfftp_plan (size_t length)
if (length==1) return plan;
if (cfftp_factorize(plan)!=0) { DEALLOC(plan); return NULL; }
size_t tws=cfftp_twsize(plan);
- plan->mem=RALLOC(cmplx,tws);
- if (!plan->mem) { DEALLOC(plan); return NULL; }
+ if (tws != 0) {
+ plan->mem=RALLOC(cmplx,tws);
+ if (!plan->mem) { DEALLOC(plan); return NULL; }
+ }
if (cfftp_comp_twiddle(plan)!=0)
{ DEALLOC(plan->mem); DEALLOC(plan); return NULL; }
return plan;
@@ -1820,7 +1822,6 @@ static size_t rfftp_twsize(rfftp_plan plan)
l1*=ip;
}
return twsize;
- return 0;
}
WARN_UNUSED_RESULT NOINLINE static int rfftp_comp_twiddle (rfftp_plan plan)
@@ -1876,8 +1877,10 @@ NOINLINE static rfftp_plan make_rfftp_plan (size_t length)
if (length==1) return plan;
if (rfftp_factorize(plan)!=0) { DEALLOC(plan); return NULL; }
size_t tws=rfftp_twsize(plan);
- plan->mem=RALLOC(double,tws);
- if (!plan->mem) { DEALLOC(plan); return NULL; }
+ if (tws != 0) {
+ plan->mem=RALLOC(double,tws);
+ if (!plan->mem) { DEALLOC(plan); return NULL; }
+ }
if (rfftp_comp_twiddle(plan)!=0)
{ DEALLOC(plan->mem); DEALLOC(plan); return NULL; }
return plan;