diff --git a/ext/standard/math.c b/ext/standard/math.c index 65187f6fa10f3..b30d518a2f47a 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 0000000000000..026af63f65c3a --- /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==