@@ -49,7 +49,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
49
49
* end, the 0's are omitted and the number of digits in num is reduced.
50
50
* In that case, may end up in the same situation as 2.
51
51
*/
52
- if (precision < 0 && num -> n_len <= labs ( precision ) ) {
52
+ if (precision < 0 && num -> n_len <= ( size_t ) ( - ( precision + Z_L ( 1 ))) + 1 ) {
53
53
* result = bc_copy_num (BCG (_zero_ ));
54
54
return ;
55
55
}
@@ -68,7 +68,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
68
68
size_t rounded_len = num -> n_len + precision ;
69
69
memcpy ((* result )-> n_value , num -> n_value , rounded_len );
70
70
71
- char * nptr = num -> n_value + rounded_len ;
71
+ const char * nptr = num -> n_value + rounded_len ;
72
72
73
73
/* Check cases that can be determined without looping. */
74
74
switch (mode ) {
@@ -88,7 +88,7 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
88
88
} else if (* nptr < 5 ) {
89
89
return ;
90
90
}
91
- /* if *nptr == 5, a loop is required for judgment . */
91
+ /* if *nptr == 5, we need to look-up further digits before making a decision . */
92
92
break ;
93
93
94
94
case PHP_ROUND_CEILING :
@@ -118,12 +118,16 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
118
118
}
119
119
/* if *nptr == 0, a loop is required for judgment. */
120
120
break ;
121
+
122
+ EMPTY_SWITCH_DEFAULT_CASE ()
121
123
}
122
124
123
125
/* Loop through the remaining digits. */
124
126
size_t count = num -> n_len + num -> n_scale - rounded_len - 1 ;
125
127
nptr ++ ;
126
- while ((count > 0 ) && (* nptr ++ == 0 )) count -- ;
128
+ while ((count > 0 ) && (* nptr ++ == 0 )) {
129
+ count -- ;
130
+ }
127
131
128
132
if (count > 0 ) {
129
133
goto up ;
@@ -147,6 +151,8 @@ void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result)
147
151
return ;
148
152
}
149
153
break ;
154
+
155
+ EMPTY_SWITCH_DEFAULT_CASE ()
150
156
}
151
157
152
158
up :
0 commit comments