Skip to content

Commit a0e6b18

Browse files
authored
fix C lint errors
Signed-off-by: Dipjyoti Das <[email protected]>
1 parent 282acf3 commit a0e6b18

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/node_modules/@stdlib/math/strided/special/sabs2/benchmark/c/benchmark.length.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ static float rand_float( void ) {
9696
*/
9797
static double benchmark( int iterations, int len ) {
9898
double elapsed;
99-
float x[ len ];
100-
float y[ len ];
99+
float *x = (float *) malloc(len * sizeof(float));
100+
float *y = (float *) malloc(len * sizeof(float));
101101
double t;
102102
int i;
103103

104+
if (x == NULL || y == NULL) {
105+
printf("Memory allocation failed.\n");
106+
exit(1);
107+
}
108+
104109
for ( i = 0; i < len; i++ ) {
105110
x[ i ] = ( rand_float()*200.0f ) - 100.0f;
106111
y[ i ] = 0.0f;
@@ -117,6 +122,11 @@ static double benchmark( int iterations, int len ) {
117122
if ( y[ 0 ] != y[ 0 ] ) {
118123
printf( "should not return NaN\n" );
119124
}
125+
126+
// 🧹 Always clean up heap allocations
127+
free(x);
128+
free(y);
129+
120130
return elapsed;
121131
}
122132

0 commit comments

Comments
 (0)