]> granicus.if.org Git - php/commitdiff
- Fixed bug #48227 (NumberFormatter::format leaks memory)
authorFelipe Pena <felipe@php.net>
Sun, 10 May 2009 20:15:39 +0000 (20:15 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 10 May 2009 20:15:39 +0000 (20:15 +0000)
ext/intl/formatter/formatter_format.c
ext/intl/tests/bug48227.phpt [new file with mode: 0644]

index 1fe9fd6a4544eb25b5ff75d83ef21229656993bf..9d6fe5729aacf70b9818023b39641cb2af38afb2 100755 (executable)
@@ -53,11 +53,7 @@ PHP_FUNCTION( numfmt_format )
 
        if(type == FORMAT_TYPE_DEFAULT) {
                if(Z_TYPE_PP(number) == IS_STRING) {
-                       SEPARATE_ZVAL_IF_NOT_REF(number);
-                       if ((Z_TYPE_PP(number)=is_numeric_string(Z_STRVAL_PP(number), Z_STRLEN_PP(number), 
-                               &Z_LVAL_PP(number), &Z_DVAL_PP(number), 1)) == 0) {
-                               ZVAL_LONG(*number, 0);
-                       }
+                       convert_scalar_to_number_ex(number);
                }
 
                if(Z_TYPE_PP(number) == IS_LONG) {
diff --git a/ext/intl/tests/bug48227.phpt b/ext/intl/tests/bug48227.phpt
new file mode 100644 (file)
index 0000000..8f633c7
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #48227 (NumberFormatter::format leaks memory)
+--FILE--
+<?php
+
+$x = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
+var_dump($x->format(''));
+var_dump($x->format(1));
+var_dump($x->format(NULL));
+var_dump($x->format($x));
+
+?>
+--EXPECTF--
+string(1) "0"
+string(1) "1"
+string(1) "0"
+
+Notice: Object of class NumberFormatter could not be converted to int in %s on line %d
+string(1) "1"