]> granicus.if.org Git - php/commitdiff
Redid the fix for #60192 with suggestions by Pierre and Kalle
authorFlorian Anderiasch <fa@php.net>
Thu, 3 Nov 2011 16:20:11 +0000 (16:20 +0000)
committerFlorian Anderiasch <fa@php.net>
Thu, 3 Nov 2011 16:20:11 +0000 (16:20 +0000)
ext/intl/collator/collator_compare.c
ext/intl/collator/collator_locale.c
ext/intl/collator/collator_sort.c
ext/intl/tests/bug60192-compare.phpt
ext/intl/tests/bug60192-getlocale.phpt
ext/intl/tests/bug60192-getsortkey.phpt
ext/intl/tests/bug60192-sort.phpt
ext/intl/tests/bug60192-sortwithsortkeys.phpt

index dcb6489032b356b2ed11bf540d3692579f35d148..4384558ac6ca87ab45b905697561d47be94c7111 100755 (executable)
@@ -58,6 +58,14 @@ PHP_FUNCTION( collator_compare )
        /* Fetch the object. */
        COLLATOR_METHOD_FETCH_OBJECT;
 
+       if (!co || !co->ucoll) {
+               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
+               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                       "Object not initialized", 0 TSRMLS_CC );
+               php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
+
+               RETURN_FALSE;
+       }
 
        /*
         * Compare given strings (converting them to UTF-16 first).
@@ -99,10 +107,6 @@ PHP_FUNCTION( collator_compare )
                RETURN_FALSE;
        }
 
-       if (!co || !co->ucoll) {
-               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
-       }
-
        /* Then compare them. */
        result = ucol_strcoll(
                co->ucoll,
index eaa7e6ba3543e37fe67e2890f63cf65834ee57a7..b30b021ee80df8b7a5383b959ba5e70aa895855f 100755 (executable)
@@ -52,7 +52,12 @@ PHP_FUNCTION( collator_get_locale )
        COLLATOR_METHOD_FETCH_OBJECT;
 
        if (!co || !co->ucoll) {
-               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
+               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
+               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                       "Object not initialized", 0 TSRMLS_CC );
+               php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
+
+               RETURN_FALSE;
        }
 
        /* Get locale by specified type. */
index 28a4a7d5727207f05f2d49cc3a81c41bc9131af6..a871c90a8ea4160e348304142e1145ad615d5038 100755 (executable)
@@ -74,7 +74,10 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2
                co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC );
 
                if (!co || !co->ucoll) {
-                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
+                       intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
+                       intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                               "Object not initialized", 0 TSRMLS_CC );
+                       php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
                }
 
                /* Compare the strings using ICU. */
@@ -391,6 +394,14 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
        /* Fetch the object. */
        COLLATOR_METHOD_FETCH_OBJECT;
 
+       if (!co || !co->ucoll) {
+               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
+               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                       "Object not initialized", 0 TSRMLS_CC );
+               php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
+
+               RETURN_FALSE;
+       }
 
        /*
         * Sort specified array.
@@ -445,10 +456,6 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
                /* Get sort key, reallocating the buffer if needed. */
                bufLeft = sortKeyBufSize - sortKeyBufOffset;
 
-               if (!co || !co->ucoll) {
-                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
-               }
-
                sortKeyLen = ucol_getSortKey( co->ucoll,
                                                                          utf16_buf,
                                                                          utf16_len,
@@ -559,6 +566,14 @@ PHP_FUNCTION( collator_get_sort_key )
        /* Fetch the object. */
        COLLATOR_METHOD_FETCH_OBJECT;
 
+       if (!co || !co->ucoll) {
+               intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
+               intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
+                       "Object not initialized", 0 TSRMLS_CC );
+               php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Object not initialized");
+
+               RETURN_FALSE;
+       }
 
        /*
         * Compare given strings (converting them to UTF-16 first).
@@ -579,10 +594,6 @@ PHP_FUNCTION( collator_get_sort_key )
                RETURN_FALSE;
        }
 
-       if (!co || !co->ucoll) {
-               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized");
-       }
-
        key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, key, 0);
        if(!key_len) {
                efree( ustr );
index d1db015d4a336f1a1ff01a83b280b2c713666f63..0fd24cce80853eae91e1f1c60faa4125b2718e76 100644 (file)
@@ -6,7 +6,6 @@ Bug #60192 (SegFault when Collator not constructed properly)
 ?>
 --FILE--
 <?php
-
 class Collator2 extends Collator{
        public function __construct() {
                // ommitting parent::__construct($someLocale);
@@ -14,7 +13,7 @@ class Collator2 extends Collator{
 }
 
 $c = new Collator2();
-$c->compare('h', 'H');
+$a = $c->compare('h', 'H');
 --EXPECTF--
 
-Fatal error: Collator::compare(): Object not initialized in %s on line %d
+Catchable fatal error: Collator::compare(): Object not initialized in %s on line %d
index 0adb09223bac703d61721693bbdfb2ca146ab9df..50e3ec35e462e0de9fe760f65d56b4ee398b4ccd 100644 (file)
@@ -17,4 +17,4 @@ $c = new Collator2();
 $c->getLocale(Locale::ACTUAL_LOCALE);
 --EXPECTF--
 
-Fatal error: Collator::getLocale(): Object not initialized in %s on line %d
+Catchable fatal error: Collator::getLocale(): Object not initialized in %s on line %d
index dedcfab8ba34a94494647da38ac8669477e61b2f..39755ae8f9704082f8cfde596036971d4435a67e 100644 (file)
@@ -17,4 +17,4 @@ $c = new Collator2();
 $c->getSortKey('h');
 --EXPECTF--
 
-Fatal error: Collator::getSortKey(): Object not initialized in %s on line %d
+Catchable fatal error: Collator::getSortKey(): Object not initialized in %s on line %d
index 35158995b613f8f2a5511e7e6945a7dffce8bd73..57057215e66dd66b396a561221d7085dc1fc1aca 100644 (file)
@@ -18,4 +18,4 @@ $a = array('a', 'b');
 $c->sort($a);
 --EXPECTF--
 
-Fatal error: Collator::sort(): Object not initialized in %s on line %d
+Catchable fatal error: Collator::sort(): Object not initialized in %s on line %d
index a82fdda79a449b5ade3cabf591f81bc6ab728072..445f4a03b9f6120648af54eafa0bc64b4eca89eb 100644 (file)
@@ -18,4 +18,4 @@ $a = array('a', 'b');
 $c->sortWithSortKeys($a);
 --EXPECTF--
 
-Fatal error: Collator::sortWithSortKeys(): Object not initialized in %s on line %d
+Catchable fatal error: Collator::sortWithSortKeys(): Object not initialized in %s on line %d