Skip to content

Commit 78720e3

Browse files
committed
Mark numeric strings as valid UTF-8
1 parent 0c9181b commit 78720e3

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Zend/zend_operators.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_long_to_str(zend_long num) /* {{{ */
32183218
} else {
32193219
char buf[MAX_LENGTH_OF_LONG + 1];
32203220
char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, num);
3221-
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3221+
zend_string *str = zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3222+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
3223+
return str;
32223224
}
32233225
}
32243226
/* }}} */
@@ -3230,7 +3232,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_ulong_to_str(zend_ulong num)
32303232
} else {
32313233
char buf[MAX_LENGTH_OF_LONG + 1];
32323234
char *res = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
3233-
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3235+
zend_string *str = zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3236+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
3237+
return str;
32343238
}
32353239
}
32363240

@@ -3272,7 +3276,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_u64_to_str(uint64_t num)
32723276
} else {
32733277
char buf[20 + 1];
32743278
char *res = zend_print_u64_to_buf(buf + sizeof(buf) - 1, num);
3275-
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3279+
zend_string *str = zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3280+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
3281+
return str;
32763282
}
32773283
}
32783284

@@ -3283,7 +3289,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_i64_to_str(int64_t num)
32833289
} else {
32843290
char buf[20 + 1];
32853291
char *res = zend_print_i64_to_buf(buf + sizeof(buf) - 1, num);
3286-
return zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3292+
zend_string *str = zend_string_init(res, buf + sizeof(buf) - 1 - res, 0);
3293+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
3294+
return str;
32873295
}
32883296
}
32893297

@@ -3293,7 +3301,9 @@ ZEND_API zend_string* ZEND_FASTCALL zend_double_to_str(double num)
32933301
/* Model snprintf precision behavior. */
32943302
int precision = (int) EG(precision);
32953303
zend_gcvt(num, precision ? precision : 1, '.', 'E', buf);
3296-
return zend_string_init(buf, strlen(buf), 0);
3304+
zend_string *str = zend_string_init(buf, strlen(buf), 0);
3305+
GC_ADD_FLAGS(str, IS_STR_VALID_UTF8);
3306+
return str;
32973307
}
32983308

32993309
ZEND_API zend_uchar ZEND_FASTCALL is_numeric_str_function(const zend_string *str, zend_long *lval, double *dval) /* {{{ */

ext/zend_test/tests/strings_marked_as_utf8.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ Known strings:
106106
bool(true)
107107
Integer cast to string:
108108
string(4) "2563"
109-
bool(false)
109+
bool(true)
110110
Float cast to string:
111111
string(4) "26.7"
112-
bool(false)
112+
bool(true)
113113
string(8) "2.0E+100"
114-
bool(false)
114+
bool(true)
115115
Concatenation known valid UTF-8 strings in variables:
116116
string(2) "fo"
117117
bool(false)

0 commit comments

Comments
 (0)