Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ext/intl/grapheme/grapheme_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,22 +1173,36 @@ U_CFUNC PHP_FUNCTION(grapheme_strrev)
p = ZSTR_VAL(ret);

ubrk_setUText(bi, ut, &ustatus);
if (U_FAILURE(ustatus)) {
intl_error_set_code(nullptr, ustatus);
intl_error_set_custom_msg(nullptr, "Error ubrk_setUText");

RETVAL_FALSE;
goto ubrk_false_end;
}

pos = ubrk_last(bi);
if (pos == UBRK_DONE) {
RETVAL_EMPTY_STRING();
goto ubrk_end;
}

current = ZSTR_LEN(string);
for (end = pstr; pos != UBRK_DONE; ) {
pos = ubrk_previous(bi);
if (pos == UBRK_DONE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance we get a test for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I think we don't need it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that due to an error condition, the loop ends early and the NUL byte will be written on a position before the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, There this is no early end. However, I found forget when ubrk_setUText is failure.

break;
}
end_len = current - pos;
for (int32_t j = 0; j < end_len; j++) {
*p++ = *(pstr + pos + j);
}
current = pos;
}
ubrk_end:
*p = '\0';
RETVAL_NEW_STR(ret);
ubrk_false_end:
ubrk_close(bi);
close:
utext_close(ut);
Expand Down
Loading