From 3c409c3696f079565ebb0b0659dfdd20f9beb18e Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 22 May 2012 23:24:42 +0200 Subject: [PATCH] Bug #62112: restore PHP 5.3 behavior --- ext/standard/math.c | 8 ++++---- ext/standard/tests/math/bug62112.phpt | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/math/bug62112.phpt diff --git a/ext/standard/math.c b/ext/standard/math.c index 65187f6fa10f..b30d518a2f47 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1137,7 +1137,7 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size } /* allow for thousand separators */ - if (thousand_sep) { + if (thousand_sep && *thousand_sep) { integral += thousand_sep_len * ((integral-1) / 3); } @@ -1146,7 +1146,7 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size if (dec) { reslen += dec; - if (dec_point) { + if (dec_point && *dec_point) { reslen += dec_point_len; } } @@ -1182,7 +1182,7 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size } /* add decimal point */ - if (dec_point) { + if (dec_point && *dec_point) { t -= dec_point_len; memcpy(t + 1, dec_point, dec_point_len); } @@ -1192,7 +1192,7 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size * separator every three digits */ while(s >= tmpbuf) { *t-- = *s--; - if (thousand_sep && (++count%3)==0 && s>=tmpbuf) { + if (thousand_sep && *thousand_sep && (++count%3)==0 && s>=tmpbuf) { t -= thousand_sep_len; memcpy(t + 1, thousand_sep, thousand_sep_len); } diff --git a/ext/standard/tests/math/bug62112.phpt b/ext/standard/tests/math/bug62112.phpt new file mode 100644 index 000000000000..026af63f65c3 --- /dev/null +++ b/ext/standard/tests/math/bug62112.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #62112: Regression in number_format() in PHP 5.4 +--FILE-- + +==DONE== +--EXPECTF-- +string(4) "2000" +string(2) "01" +==DONE==