summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2017-09-11 23:51:19 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2017-09-11 23:52:14 +0200
commit77f3cef35ced72f4aa873427ec053763ed3f3771 (patch)
treeb7c274013b7aa5fa68c8c8315bfe8e5e4df06ad9
parent613bac9eb36d9aae6a7d91bd3852865f44106d12 (diff)
parent87a91aef835c2c361e93b4352636f0dcb3275ac9 (diff)
downloadphp-git-77f3cef35ced72f4aa873427ec053763ed3f3771.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fixed bug #46781 (BC math handles minus zero incorrectly)
-rw-r--r--NEWS1
-rw-r--r--ext/bcmath/libbcmath/src/str2num.c3
-rw-r--r--ext/bcmath/tests/bug46781.phpt16
3 files changed, 20 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 0f7b58aa9c..96bd6b1fb3 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,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 ef505e86e1..62544de80e 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 0000000000..caffe83860
--- /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===