From: Florian Anderiasch Date: Thu, 3 Nov 2011 16:20:11 +0000 (+0000) Subject: Redid the fix for #60192 with suggestions by Pierre and Kalle X-Git-Tag: php-5.3.9RC2~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=635e2c28fec5a56f0b5aaa5ae7c60fa78808c9d5;p=php Redid the fix for #60192 with suggestions by Pierre and Kalle --- diff --git a/ext/intl/collator/collator_compare.c b/ext/intl/collator/collator_compare.c index dcb6489032..4384558ac6 100755 --- a/ext/intl/collator/collator_compare.c +++ b/ext/intl/collator/collator_compare.c @@ -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, diff --git a/ext/intl/collator/collator_locale.c b/ext/intl/collator/collator_locale.c index eaa7e6ba35..b30b021ee8 100755 --- a/ext/intl/collator/collator_locale.c +++ b/ext/intl/collator/collator_locale.c @@ -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. */ diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index 28a4a7d572..a871c90a8e 100755 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -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 ); diff --git a/ext/intl/tests/bug60192-compare.phpt b/ext/intl/tests/bug60192-compare.phpt index d1db015d4a..0fd24cce80 100644 --- a/ext/intl/tests/bug60192-compare.phpt +++ b/ext/intl/tests/bug60192-compare.phpt @@ -6,7 +6,6 @@ Bug #60192 (SegFault when Collator not constructed properly) ?> --FILE-- 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 diff --git a/ext/intl/tests/bug60192-getlocale.phpt b/ext/intl/tests/bug60192-getlocale.phpt index 0adb09223b..50e3ec35e4 100644 --- a/ext/intl/tests/bug60192-getlocale.phpt +++ b/ext/intl/tests/bug60192-getlocale.phpt @@ -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 diff --git a/ext/intl/tests/bug60192-getsortkey.phpt b/ext/intl/tests/bug60192-getsortkey.phpt index dedcfab8ba..39755ae8f9 100644 --- a/ext/intl/tests/bug60192-getsortkey.phpt +++ b/ext/intl/tests/bug60192-getsortkey.phpt @@ -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 diff --git a/ext/intl/tests/bug60192-sort.phpt b/ext/intl/tests/bug60192-sort.phpt index 35158995b6..57057215e6 100644 --- a/ext/intl/tests/bug60192-sort.phpt +++ b/ext/intl/tests/bug60192-sort.phpt @@ -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 diff --git a/ext/intl/tests/bug60192-sortwithsortkeys.phpt b/ext/intl/tests/bug60192-sortwithsortkeys.phpt index a82fdda79a..445f4a03b9 100644 --- a/ext/intl/tests/bug60192-sortwithsortkeys.phpt +++ b/ext/intl/tests/bug60192-sortwithsortkeys.phpt @@ -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