com php-src: Added -1 safety check, fixed test: ext/standard/math.c ext/standard/tests/math/intdiv.phpt

From: Date: Tue, 15 Jul 2014 12:53:24 +0000
Subject: com php-src: Added -1 safety check, fixed test: ext/standard/math.c ext/standard/tests/math/intdiv.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-79758@lists.php.net to get a copy of this message
Commit: 7148a4cf0338d5159c04da321682ce43dabccb36 Author: Andrea Faulds <ajf@ajf.me> Tue, 15 Jul 2014 13:53:24 +0100 Parents: 6692d15e26358867f3b28d5ca83730cf156fdaf6 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7148a4cf0338d5159c04da321682ce43dabccb36 Log: Added -1 safety check, fixed test Changed paths: M ext/standard/math.c M ext/standard/tests/math/intdiv.phpt Diff: diff --git a/ext/standard/math.c b/ext/standard/math.c index e8260ec..8a4b045 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1260,6 +1260,10 @@ PHP_FUNCTION(intdiv) if (divisor == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero"); RETURN_BOOL(0); + } else if (divisor == -1 && numerator == LONG_MIN) { + /* Prevent overflow error/crash + We don't return a float here as that violates function contract */ + RETURN_LONG(0); } RETURN_LONG(numerator/divisor); diff --git a/ext/standard/tests/math/intdiv.phpt b/ext/standard/tests/math/intdiv.phpt index 449434d..d37d2e8 100644 --- a/ext/standard/tests/math/intdiv.phpt +++ b/ext/standard/tests/math/intdiv.phpt @@ -8,6 +8,7 @@ var_dump(intdiv(3, -2)); var_dump(intdiv(-3, -2)); var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX)); var_dump(intdiv(-PHP_INT_MAX - 1, -PHP_INT_MAX - 1)); +var_dump(intdiv(-PHP_INT_MAX - 1, -1)); var_dump(intdiv(1, 0)); ?> @@ -18,6 +19,7 @@ int(-1) int(1) int(1) int(1) +int(0) -Warning: Division by zero in %s on line 8 +Warning: intdiv(): Division by zero in %s on line 9 bool(false)

« previous php.cvs (#79758) next »