diff --git a/lib/node_modules/@stdlib/math/strided/special/dfloor/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/math/strided/special/dfloor/benchmark/c/benchmark.length.c index dc6a43486daa..a802f7519c12 100644 --- a/lib/node_modules/@stdlib/math/strided/special/dfloor/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/math/strided/special/dfloor/benchmark/c/benchmark.length.c @@ -114,11 +114,24 @@ float rand_uniformf( float a, float b ) { */ static double benchmark( int iterations, int len ) { double elapsed; - double x[ len ]; - double y[ len ]; + double *x; + double *y; double t; int i; + // Allocate memory dynamically to avoid stack overflow + x = malloc( len * sizeof(double) ); + if ( x == NULL ) { + printf( "Error: failed to allocate memory for x array\n" ); + return -1.0; + } + y = malloc( len * sizeof(double) ); + if ( y == NULL ) { + printf( "Error: failed to allocate memory for y array\n" ); + free( x ); + return -1.0; + } + for ( i = 0; i < len; i++ ) { x[ i ] = rand_uniform( -10.0, 10.0 ); y[ i ] = 0.0; @@ -136,6 +149,9 @@ static double benchmark( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + // Free allocated memory + free( x ); + free( y ); return elapsed; } @@ -162,6 +178,10 @@ int main( void ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); elapsed = benchmark( iter, len ); + if ( elapsed < 0.0 ) { + printf( "not ok %d benchmark failed - memory allocation error\n", count ); + continue; + } print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); }