Skip to content

Commit 8740533

Browse files
committed
Avoid more UB in round()
1 parent 4b5e824 commit 8740533

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Zend/zend_strtod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ zend_strtod
27052705
L = c - '0';
27062706
s1 = s;
27072707
while((c = *++s) >= '0' && c <= '9')
2708-
L = 10*L + c - '0';
2708+
L = 10*L + (c - '0');
27092709
if (s - s1 > 8 || L > 19999)
27102710
/* Avoid confusion from exponents
27112711
* so large that e might overflow.

ext/standard/math.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
141141
/* If the decimal precision guaranteed by FP arithmetic is higher than
142142
the requested places BUT is small enough to make sure a non-zero value
143143
is returned, pre-round the result to the precision */
144-
if (precision_places > places && precision_places - places < 15) {
144+
if (precision_places > places && precision_places - 15 < places) {
145145
int64_t use_precision = precision_places < INT_MIN+1 ? INT_MIN+1 : precision_places;
146146

147147
f2 = php_intpow10(abs((int)use_precision));

0 commit comments

Comments
 (0)