@@ -33,6 +33,9 @@ copy_data(char* in, npy_intp step_in, npy_intp nin,
33
33
char * out , npy_intp step_out , npy_intp nout , npy_intp elsize )
34
34
{
35
35
npy_intp ncopy = nin <= nout ? nin : nout ;
36
+ if (ncopy <= 0 ) {
37
+ return ; /* safety, and indeed required for npts=1 in irfft */
38
+ }
36
39
if (step_in == elsize && step_out == elsize ) {
37
40
memcpy (out , in , ncopy * elsize );
38
41
}
@@ -235,11 +238,11 @@ irfft_loop(char **args, npy_intp const *dimensions, npy_intp const *steps, void
235
238
double * op_double = (double * )op_or_buff ;
236
239
/* Copy complex input to buffer in FFTpack order */
237
240
op_double [0 ] = ((double * )ip )[0 ];
238
- if (nin > 1 ) {
241
+ if (npts > 1 ) {
239
242
copy_data (ip + step_in , step_in , nin - 2 ,
240
243
(char * )& op_double [1 ], sizeof (npy_cdouble ), npts / 2 - 1 ,
241
244
sizeof (npy_cdouble ));
242
- npy_intp ncopied = (npts / 2 - 1 < nin - 2 ? npts / 2 - 1 : nin - 2 );
245
+ npy_intp ncopied = (npts / 2 - 1 < nin - 2 ? npts / 2 - 1 : nin - 2 );
243
246
double * last = (double * )(ip + (ncopied + 1 ) * step_in );
244
247
op_double [ncopied * 2 + 1 ] = last [0 ];
245
248
if (npts % 2 == 1 ) { /* For odd n, we still imag real of the last point */
0 commit comments