Skip to content

Commit 006870c

Browse files
committed
Fixed array allocation
1 parent b5653e8 commit 006870c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ext/bcmath/libbcmath/src/recmul.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,9 @@ static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, int n2len, bc_nu
100100
size_t n2_arr_size = n2len / BC_LONGABLE_DIGITS + (n2len % BC_LONGABLE_DIGITS ? 1 : 0);
101101
size_t prod_arr_size = n1_arr_size + n2_arr_size - 1;
102102

103-
unsigned long n1_l[n1_arr_size];
104-
unsigned long n2_l[n2_arr_size];
105-
unsigned long prod_l[prod_arr_size];
106-
for (i = 0; i < prod_arr_size; i++) {
107-
prod_l[i] = 0;
108-
}
103+
unsigned long *n1_l = emalloc(n1_arr_size * sizeof(unsigned long));
104+
unsigned long *n2_l = emalloc(n2_arr_size * sizeof(unsigned long));
105+
unsigned long *prod_l = ecalloc(prod_arr_size, sizeof(unsigned long));
109106

110107
/* Convert n1 to long[] */
111108
i = 0;
@@ -164,6 +161,10 @@ static void bc_standard_mul(bc_num n1, size_t n1len, bc_num n2, int n2len, bc_nu
164161
*pend-- = prod_l[i] % BASE;
165162
prod_l[i] /= BASE;
166163
}
164+
165+
efree(n1_l);
166+
efree(n2_l);
167+
efree(prod_l);
167168
}
168169

169170
/* The multiply routine. N2 times N1 is put int PROD with the scale of

0 commit comments

Comments
 (0)