Skip to content

Commit 2556951

Browse files
committed
Address comments
1 parent d203371 commit 2556951

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

ext/bcmath/libbcmath/src/raise.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ static bc_num bc_standard_raise(
102102
const char *base_ptr, const char *base_end, long exponent, size_t base_len, size_t power_scale)
103103
{
104104
/* Remove the leading zeros as they will be filled in later. */
105-
while (*base_ptr++ == 0) {
105+
while (*base_ptr == 0) {
106+
base_ptr++;
106107
base_len--;
107108
}
108109

109110
size_t base_arr_size = BC_ARR_SIZE_FROM_LEN(base_len);
110111
size_t max_power_arr_size = base_arr_size * exponent;
111112

112113
/* The allocated memory area is reused on a rotational basis, so the same size is required. */
113-
BC_VECTOR *buf = safe_emalloc(max_power_arr_size * 3, sizeof(BC_VECTOR), 0);
114+
BC_VECTOR *buf = safe_emalloc(max_power_arr_size, sizeof(BC_VECTOR) * 3, 0);
114115
BC_VECTOR *base_vector = buf;
115116
BC_VECTOR *power_vector = base_vector + max_power_arr_size;
116117
BC_VECTOR *tmp_result_vector = power_vector + max_power_arr_size;
@@ -155,14 +156,8 @@ static bc_num bc_standard_raise(
155156
char *pend = pptr + power_full_len - 1;
156157

157158
/* Pad with leading zeros if necessary. */
158-
while (power_leading_zeros > sizeof(uint32_t)) {
159-
bc_write_bcd_representation(0, pptr);
160-
pptr += sizeof(uint32_t);
161-
power_leading_zeros -= sizeof(uint32_t);
162-
}
163-
for (size_t i = 0; i < power_leading_zeros; i++) {
164-
*pptr++ = 0;
165-
}
159+
memset(pptr, 0, power_leading_zeros);
160+
pptr += power_leading_zeros;
166161

167162
bc_convert_vector_to_char(power_vector, pptr, pend, power_arr_size);
168163

0 commit comments

Comments
 (0)