Skip to content

Commit c927d24

Browse files
ext/bcmath: Use const qualifiers appropriately (#18284)
1 parent 10b2754 commit c927d24

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

ext/bcmath/bcmath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ static zend_always_inline bcmath_number_obj_t *bcmath_number_new_obj(bc_num ret,
11641164
return intern;
11651165
}
11661166

1167-
static zend_result bcmath_number_parse_num(zval *zv, zend_object **obj, zend_string **str, zend_long *lval)
1167+
static zend_result bcmath_number_parse_num(const zval *zv, zend_object **obj, zend_string **str, zend_long *lval)
11681168
{
11691169
if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), bcmath_number_ce)) {
11701170
*obj = Z_OBJ_P(zv);
@@ -1372,7 +1372,7 @@ static int bcmath_number_compare(zval *op1, zval *op2)
13721372
}
13731373

13741374
static zend_always_inline zend_result bc_num_from_obj_or_str_or_long_with_err(
1375-
bc_num *num, size_t *scale, zend_object *obj, zend_string *str, zend_long lval, uint32_t arg_num)
1375+
bc_num *num, size_t *scale, const zend_object *obj, const zend_string *str, zend_long lval, uint32_t arg_num)
13761376
{
13771377
size_t full_scale = 0;
13781378
if (UNEXPECTED(bc_num_from_obj_or_str_or_long(num, &full_scale, obj, str, lval) == FAILURE)) {

ext/bcmath/libbcmath/src/compare.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141

4242
bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool use_sign)
4343
{
44-
char *n1ptr, *n2ptr;
45-
4644
/* First, compare signs. */
4745
if (use_sign && n1->n_sign != n2->n_sign) {
4846
/*
@@ -91,8 +89,8 @@ bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool us
9189
/* If we get here, they have the same number of integer digits.
9290
check the integer part and the equal length part of the fraction. */
9391
size_t count = n1->n_len + MIN (n1_scale, n2_scale);
94-
n1ptr = n1->n_value;
95-
n2ptr = n2->n_value;
92+
const char *n1ptr = n1->n_value;
93+
const char *n2ptr = n2->n_value;
9694

9795
while ((count > 0) && (*n1ptr == *n2ptr)) {
9896
n1ptr++;

ext/bcmath/libbcmath/src/div.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline void bc_fast_div(
7070
*/
7171
static inline void bc_standard_div(
7272
BC_VECTOR *numerator_vectors, size_t numerator_arr_size,
73-
BC_VECTOR *divisor_vectors, size_t divisor_arr_size, size_t divisor_len,
73+
const BC_VECTOR *divisor_vectors, size_t divisor_arr_size, size_t divisor_len,
7474
BC_VECTOR *quot_vectors, size_t quot_arr_size
7575
) {
7676
size_t numerator_top_index = numerator_arr_size - 1;
@@ -354,10 +354,10 @@ bool bc_divide(bc_num numerator, bc_num divisor, bc_num *quot, size_t scale)
354354
return true;
355355
}
356356

357-
char *numeratorptr = numerator->n_value;
357+
const char *numeratorptr = numerator->n_value;
358358
size_t numerator_size = numerator->n_len + quot_scale + divisor->n_scale;
359359

360-
char *divisorptr = divisor->n_value;
360+
const char *divisorptr = divisor->n_value;
361361
size_t divisor_size = divisor->n_len + divisor->n_scale;
362362

363363
/* check and remove numerator leading zeros */

ext/bcmath/libbcmath/src/doaddsub.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ bc_num _bc_do_add(bc_num n1, bc_num n2)
4646
size_t min_len = MIN (n1->n_len, n2->n_len);
4747
size_t min_scale = MIN(n1->n_scale, n2->n_scale);
4848
size_t min_bytes = min_len + min_scale;
49-
char *n1ptr, *n2ptr, *sumptr;
49+
char *sumptr;
5050
bool carry = 0;
5151
size_t count;
5252

5353
/* Prepare sum. */
5454
sum = bc_new_num_nonzeroed(sum_len, sum_scale);
5555

5656
/* Start with the fraction part. Initialize the pointers. */
57-
n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1);
58-
n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1);
57+
const char *n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1);
58+
const char *n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1);
5959
sumptr = (char *) (sum->n_value + sum_scale + sum_len - 1);
6060

6161
/* Add the fraction part. First copy the longer fraction.*/
@@ -182,14 +182,14 @@ bc_num _bc_do_sub(bc_num n1, bc_num n2)
182182
size_t borrow = 0;
183183
size_t count;
184184
int val;
185-
char *n1ptr, *n2ptr, *diffptr;
185+
char *diffptr;
186186

187187
/* Allocate temporary storage. */
188188
diff = bc_new_num_nonzeroed(diff_len, diff_scale);
189189

190190
/* Initialize the subtract. */
191-
n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1);
192-
n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1);
191+
const char *n1ptr = (char *) (n1->n_value + n1->n_len + n1->n_scale - 1);
192+
const char *n2ptr = (char *) (n2->n_value + n2->n_len + n2->n_scale - 1);
193193
diffptr = (char *) (diff->n_value + diff_len + diff_scale - 1);
194194

195195
/* Take care of the longer scaled number. */

0 commit comments

Comments
 (0)