Redid the fix for #60192 with suggestions by Pierre and Kalle

This commit is contained in:
Florian Anderiasch 2011-11-03 16:20:11 +00:00
parent 10a1121a37
commit 8343d05e85
8 changed files with 42 additions and 23 deletions

View File

@ -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,

View File

@ -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. */

View File

@ -73,9 +73,12 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2
/* Fetch collator object. */
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");
}
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");
}
/* Compare the strings using ICU. */
result->value.lval = ucol_strcoll(
@ -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 );

View 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

View 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

View 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

View 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

View 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