Skip to content

Commit ec2346f

Browse files
committed
feedback
1 parent 844fe24 commit ec2346f

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

main/streams/streams.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,9 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
142142

143143
zend_string *php_stream_escape_persistent_key(const char *host, size_t hostlen)
144144
{
145-
size_t escaped_len = 0, i;
146-
for (i = 0; i < hostlen; i++) {
147-
escaped_len += (host[i] == '\0' || host[i] == '\\') ? 2 : 1;
148-
}
149-
150-
zend_string *escaped = zend_string_alloc(escaped_len, 0);
145+
zend_string *escaped = zend_string_safe_alloc(hostlen, 2, 0, 0);
151146
char *ptr = ZSTR_VAL(escaped);
152-
for (i = 0; i < hostlen; i++) {
147+
for (size_t i = 0; i < hostlen; i++) {
153148
if (host[i] == '\0') {
154149
*ptr++ = '\\';
155150
*ptr++ = '0';
@@ -161,6 +156,7 @@ zend_string *php_stream_escape_persistent_key(const char *host, size_t hostlen)
161156
}
162157
}
163158
*ptr = '\0';
159+
ZSTR_LEN(escaped) = ptr - ZSTR_VAL(escaped);
164160

165161
return escaped;
166162
}

0 commit comments

Comments
 (0)