com php-src: Fixed bug #46781 (BC math handles minus zero incorrectly): NEWS ext/bcmath/libbcmath/src/str2num.c ext/bcmath/tests/bug46781.phpt
| From: | Christoph Michael Becker | Date: | Mon, 11 Sep 2017 21:44:23 +0000 |
| Subject: | com php-src: Fixed bug #46781 (BC math handles minus zero incorrectly): NEWS ext/bcmath/libbcmath/src/str2num.c ext/bcmath/tests/bug46781.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99359@lists.php.net to get a copy of this message | ||
Commit: 9aa6898b9be78bb1e138488c3204bb745a31aca7
Author: Christoph M. Becker <cmbecker69@gmx.de> Mon, 11 Sep 2017 23:44:23 +0200
Parents: d103802003aaa808e07e52d957e346fe4fb75952
Branches: PHP-7.0 PHP-7..1 PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9aa6898b9be78bb1e138488c3204bb745a31aca7
Log:
Fixed bug #46781 (BC math handles minus zero incorrectly)
Actually, there is no negative zero at all. We obey Postel's law, and
still accept negative zeroes, but we store them as positive zeroes
after the conversion from string, i.e. we normalize before further
processing.
Bugs:
https://bugs.php.net/46781
Changed paths:
M NEWS
M ext/bcmath/libbcmath/src/str2num.c
A ext/bcmath/tests/bug46781.phpt
Diff:
diff --git a/NEWS b/NEWS
index 12c5003..a866e5c 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PHP NEWS
- BCMath:
. Fixed bug #44995 (bcpowmod() fails if scale != 0). (cmb)
+ . Fixed bug #46781 (BC math handles minus zero incorrectly). (cmb)
. Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1). (okano1220, cmb)
. Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus). (cmb)
diff --git a/ext/bcmath/libbcmath/src/str2num.c b/ext/bcmath/libbcmath/src/str2num.c
index ef505e8..62544de 100644
--- a/ext/bcmath/libbcmath/src/str2num.c
+++ b/ext/bcmath/libbcmath/src/str2num.c
@@ -105,5 +105,8 @@ bc_str2num (bc_num *num, char *str, int scale)
for (;strscale > 0; strscale--)
*nptr++ = CH_VAL(*ptr++);
}
+
+ if (bc_is_zero (*num))
+ (*num)->n_sign = PLUS;
}
diff --git a/ext/bcmath/tests/bug46781.phpt b/ext/bcmath/tests/bug46781.phpt
new file mode 100644
index 0000000..caffe83
--- /dev/null
+++ b/ext/bcmath/tests/bug46781.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #46781 (BC math handles minus zero incorrectly)
+--SKIPIF--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension is not available');
+?>
+--FILE--
+<?php
+var_dump(bcadd('-0.0', '-0.0', 1));
+var_dump(bccomp('-0.0', '0', 1));
+?>
+===DONE===
+--EXPECT--
+string(3) "0.0"
+int(0)
+===DONE===