From 9aa6898b9be78bb1e138488c3204bb745a31aca7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 11 Sep 2017 23:44:23 +0200 Subject: 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. --- NEWS | 1 + ext/bcmath/libbcmath/src/str2num.c | 3 +++ ext/bcmath/tests/bug46781.phpt | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 ext/bcmath/tests/bug46781.phpt diff --git a/NEWS b/NEWS index 12c5003acc..a866e5c8b3 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 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-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(3) "0.0" +int(0) +===DONE=== -- cgit v1.2.1