Skip to content

Commit b5cdd24

Browse files
committed
UNEXPECTED conditions
1 parent 1029ddb commit b5cdd24

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ext/standard/math.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
235235
return SUCCESS;
236236
}
237237

238-
if (-places > sizeof(powers) / sizeof(powers[0]) - 1) {
238+
if (UNEXPECTED(-places > sizeof(powers) / sizeof(powers[0]) - 1)) {
239239
// Special case for rounding to the same number of places as max length possible
240240
// as this would overflow the power of 10
241241
if (places == -MAX_LENGTH_OF_LONG + 1) {
@@ -244,7 +244,7 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
244244
tmp_value = 0;
245245
power_half = powers[-places - 1] * 5;
246246
} else {
247-
// Rounding more places will allways be zero
247+
// Rounding more places will always be zero
248248
*result = 0;
249249
return SUCCESS;
250250
}
@@ -261,17 +261,17 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
261261
|| (mode == PHP_ROUND_HALF_EVEN && (rest > power_half || (rest == power_half && tmp_value % 2 == 1)))
262262
|| (mode == PHP_ROUND_HALF_ODD && (rest > power_half || (rest == power_half && tmp_value % 2 == 0)))
263263
) {
264-
if (max_places) {
264+
if (UNEXPECTED(max_places)) {
265265
return FAILURE; // would overflow
266266
}
267267

268268
tmp_value = tmp_value * power;
269269

270-
if (tmp_value > ZEND_LONG_MAX - power) {
270+
if (UNEXPECTED(tmp_value > ZEND_LONG_MAX - power)) {
271271
return FAILURE; // would overflow
272272
}
273273
tmp_value = tmp_value + power;
274-
} else if (max_places) {
274+
} else if (UNEXPECTED(max_places)) {
275275
tmp_value = 0;
276276
} else {
277277
tmp_value = tmp_value * power;
@@ -282,18 +282,18 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
282282
|| (mode == PHP_ROUND_HALF_EVEN && (rest < -power_half || (rest == -power_half && tmp_value % 2 == -1)))
283283
|| (mode == PHP_ROUND_HALF_ODD && (rest < -power_half || (rest == -power_half && tmp_value % 2 == 0)))
284284
) {
285-
if (max_places) {
285+
if (UNEXPECTED(max_places)) {
286286
return FAILURE; // would underflow
287287
}
288288

289289
tmp_value = tmp_value * power;
290290

291-
if (tmp_value < ZEND_LONG_MIN + power) {
291+
if (UNEXPECTED(tmp_value < ZEND_LONG_MIN + power)) {
292292
return FAILURE; // would underflow
293293
}
294294

295295
tmp_value = tmp_value - power;
296-
} else if (max_places) {
296+
} else if (UNEXPECTED(max_places)) {
297297
tmp_value = 0;
298298
} else {
299299
tmp_value = tmp_value * power;

0 commit comments

Comments
 (0)