Conversation
|
i.e. static zend_always_inline zend_result collator_check_initialized(
Collator_object *co)
{
ZEND_ASSERT(co != NULL);
if (UNEXPECTED(co->ucoll == NULL)) {
intl_error_set_code(NULL, COLLATOR_ERROR_CODE(co));
intl_errors_set_custom_msg(
COLLATOR_ERROR_P(co), "Object not initialized", 0);
zend_throw_error(NULL, "Object not initialized");
return FAILURE;
}
return SUCCESS;
} |
16a26e7 to
a5ba67d
Compare
|
Added Left the pre-existing guards in collator_compare.c, collator_locale.c and collator_sort.c alone for now. The one in collator_sort.c uses a shorter shape that throws without setting the intl error state, so folding those in would change observable error state rather than just dedupe. |
LamentXU123
left a comment
There was a problem hiding this comment.
Several small suggestions.
a. Can we utilize this helper in other functions? compare()? getLocale()?
b. Could you also extend the test to cover collator_get_attribute(), collator_set_attribute(), collator_get_strength(), and collator_set_strength() with an unconstructed Collator?
a5ba67d to
d43a043
Compare
|
Done for compare(), getLocale(), sortWithSortKeys() and getSortKey(). Left the one in Test now covers collator_get_attribute(), collator_set_attribute(), collator_get_strength() and collator_set_strength() alongside the methods. |
|
can |
…hods Collator::getAttribute(), setAttribute(), getStrength() and setStrength() dereferenced a NULL ICU collator when called on an object whose constructor skipped parent::__construct(), returning bogus values instead of failing, while compare(), getLocale(), sort() and getSortKey() already throw "Object not initialized". Apply the same guard to the four remaining methods through a collator_check_initialized() helper, which also replaces the five existing copies. sort() and asort() carried a shorter variant that threw without recording the failure, so they now set the object's intl error state like every other method. Closes phpGH-23797
d43a043 to
014133d
Compare
|
Done in 014133d. One behavior change to note: the helper also sets the intl error state, so sort() and asort() now emit the diagnostic under a non-default If you'd rather 8.4 kept to the four attribute methods and the sort_internal() conversion went to master, I'll split it (I think that is best). |
|
indeed |
Collator::getAttribute(), setAttribute(), getStrength() and setStrength() reach ICU with a NULL collator when a subclass skips parent::__construct(), so getAttribute() returns -1 and setStrength() reports success on an object that cannot collate. The four methods that already check, compare(), getLocale(), sort() and getSortKey(), throw "Object not initialized"; this applies the same guard to the remaining four. COLLATOR_METHOD_FETCH_OBJECT does not check on its own.