Skip to content

Commit 2dc8acc

Browse files
committed
Fix invalid condition for zend_string_truncate in php_repr_str
1 parent 5aa31c8 commit 2dc8acc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/standard/string.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,7 +3875,8 @@ PHPAPI zend_string *php_repr_str(const char *str, size_t len) {
38753875
// so we need 4 bytes for each character
38763876
// plus 2 byte for the leading quote and the trailing quote
38773877
// plus 1 byte for the null terminator
3878-
zend_string *new_str = zend_string_alloc(len * 4 + 2 + 1, 0);
3878+
int alloc_len = len * 4 + 2 + 1;
3879+
zend_string *new_str = zend_string_alloc(alloc_len, 0);
38793880
char *target = ZSTR_VAL(new_str);
38803881
// add the leading quote
38813882
*target++ = '"';
@@ -3890,7 +3891,7 @@ PHPAPI zend_string *php_repr_str(const char *str, size_t len) {
38903891
// add the null terminator
38913892
*target = '\0';
38923893
newlen = target - ZSTR_VAL(new_str);
3893-
if (newlen < len * 4) {
3894+
if (newlen < alloc_len) {
38943895
new_str = zend_string_truncate(new_str, newlen, 0);
38953896
}
38963897
return new_str;

0 commit comments

Comments
 (0)