Skip to content

Commit e6d57bf

Browse files
authored
Update zend_string.h
1 parent db0c398 commit e6d57bf

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

Zend/zend_string.h

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -318,39 +318,29 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
318318
}
319319

320320
static zend_always_inline char *zend_cstr_append_char(const char *str, size_t len, char c) {
321-
char *res = (char *)safe_emalloc(len, 1, 2);
322-
if (len > 0) {
323-
zend_mempcpy(res, str, len);
324-
}
325-
res[len] = c;
326-
res[len + 1] = '\0';
321+
char *res = (char *)safe_emalloc(len + 2, 1, 0);
322+
char *p = zend_mempcpy(res, str, len);
323+
*p++ = c;
324+
*p = '\0';
327325
return res;
328326
}
329327

330328
static zend_always_inline char *zend_cstr_concat(const char *s1, size_t len1, const char *s2, size_t len2) {
331-
char *res = (char *)safe_emalloc(len1, 1, len2 + 1);
332-
if (len1 > 0) {
333-
zend_mempcpy(res, s1, len1);
334-
}
335-
if (len2 > 0) {
336-
zend_mempcpy(res + len1, s2, len2);
337-
}
338-
res[len1 + len2] = '\0';
329+
char *res = (char *)safe_emalloc(len1 + len2 + 1, 1, 0);
330+
char *p = res;
331+
p = zend_mempcpy(p, s1, len1);
332+
p = zend_mempcpy(p, s2, len2);
333+
*p = '\0';
339334
return res;
340335
}
341336

342337
static zend_always_inline char *zend_cstr_concat3(const char *s1, size_t len1, const char *s2, size_t len2, const char *s3, size_t len3) {
343-
char *res = (char *)safe_emalloc(len1, 1, len2 + len3 + 1);
344-
if (len1 > 0) {
345-
zend_mempcpy(res, s1, len1);
346-
}
347-
if (len2 > 0) {
348-
zend_mempcpy(res + len1, s2, len2);
349-
}
350-
if (len3 > 0) {
351-
zend_mempcpy(res + len1 + len2, s3, len3);
352-
}
353-
res[len1 + len2 + len3] = '\0';
338+
char *res = (char *)safe_emalloc(len1 + len2 + len3 + 1, 1, 0);
339+
char *p = res;
340+
p = zend_mempcpy(p, s1, len1);
341+
p = zend_mempcpy(p, s2, len2);
342+
p = zend_mempcpy(p, s3, len3);
343+
*p = '\0';
354344
return res;
355345
}
356346

0 commit comments

Comments
 (0)