Skip to content

Commit 2483a75

Browse files
committed
UNEXPECTED conditions
1 parent db98d1d commit 2483a75

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
@@ -280,7 +280,7 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
280280
return SUCCESS;
281281
}
282282

283-
if (-places > sizeof(powers) / sizeof(powers[0]) - 1) {
283+
if (UNEXPECTED(-places > sizeof(powers) / sizeof(powers[0]) - 1)) {
284284
// Special case for rounding to the same number of places as max length possible
285285
// as this would overflow the power of 10
286286
if (places == -MAX_LENGTH_OF_LONG + 1) {
@@ -289,7 +289,7 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
289289
tmp_value = 0;
290290
power_half = powers[-places - 1] * 5;
291291
} else {
292-
// Rounding more places will allways be zero
292+
// Rounding more places will always be zero
293293
*result = 0;
294294
return SUCCESS;
295295
}
@@ -306,17 +306,17 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
306306
|| (mode == PHP_ROUND_HALF_EVEN && (rest > power_half || (rest == power_half && tmp_value % 2 == 1)))
307307
|| (mode == PHP_ROUND_HALF_ODD && (rest > power_half || (rest == power_half && tmp_value % 2 == 0)))
308308
) {
309-
if (max_places) {
309+
if (UNEXPECTED(max_places)) {
310310
return FAILURE; // would overflow
311311
}
312312

313313
tmp_value = tmp_value * power;
314314

315-
if (tmp_value > ZEND_LONG_MAX - power) {
315+
if (UNEXPECTED(tmp_value > ZEND_LONG_MAX - power)) {
316316
return FAILURE; // would overflow
317317
}
318318
tmp_value = tmp_value + power;
319-
} else if (max_places) {
319+
} else if (UNEXPECTED(max_places)) {
320320
tmp_value = 0;
321321
} else {
322322
tmp_value = tmp_value * power;
@@ -327,18 +327,18 @@ PHPAPI zend_result _php_math_round_long(zend_long value, int places, int mode, z
327327
|| (mode == PHP_ROUND_HALF_EVEN && (rest < -power_half || (rest == -power_half && tmp_value % 2 == -1)))
328328
|| (mode == PHP_ROUND_HALF_ODD && (rest < -power_half || (rest == -power_half && tmp_value % 2 == 0)))
329329
) {
330-
if (max_places) {
330+
if (UNEXPECTED(max_places)) {
331331
return FAILURE; // would underflow
332332
}
333333

334334
tmp_value = tmp_value * power;
335335

336-
if (tmp_value < ZEND_LONG_MIN + power) {
336+
if (UNEXPECTED(tmp_value < ZEND_LONG_MIN + power)) {
337337
return FAILURE; // would underflow
338338
}
339339

340340
tmp_value = tmp_value - power;
341-
} else if (max_places) {
341+
} else if (UNEXPECTED(max_places)) {
342342
tmp_value = 0;
343343
} else {
344344
tmp_value = tmp_value * power;

0 commit comments

Comments
 (0)