Skip to content

Commit 283020c

Browse files
committed
back to memcpy
1 parent 79f2b04 commit 283020c

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

Zend/zend_string.h

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,40 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
319319
}
320320

321321
static zend_always_inline char *zend_cstr_append_char(const char *str, size_t len, char c) {
322-
char *res = (char *)safe_emalloc(len + 2, 1, 0);
323-
char *p = zend_mempcpy(res, str, len);
324-
*p++ = c;
325-
*p = '\0';
326-
return res;
322+
char *res = (char *)safe_emalloc(len, 1, 2);
323+
if (len > 0) {
324+
memcpy(res, str, len);
325+
}
326+
res[len] = c;
327+
res[len + 1] = '\0';
328+
return res;
327329
}
328330

329331
static zend_always_inline char *zend_cstr_concat(const char *s1, size_t len1, const char *s2, size_t len2) {
330-
char *res = (char *)safe_emalloc(len1 + len2 + 1, 1, 0);
331-
char *p = res;
332-
p = zend_mempcpy(p, s1, len1);
333-
p = zend_mempcpy(p, s2, len2);
334-
*p = '\0';
335-
return res;
332+
char *res = (char *)safe_emalloc(len1, 1, len2 + 1);
333+
if (len1 > 0) {
334+
memcpy(res, s1, len1);
335+
}
336+
if (len2 > 0) {
337+
memcpy(res + len1, s2, len2);
338+
}
339+
res[len1 + len2] = '\0';
340+
return res;
336341
}
337342

338343
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) {
339-
char *res = (char *)safe_emalloc(len1 + len2 + len3 + 1, 1, 0);
340-
char *p = res;
341-
p = zend_mempcpy(p, s1, len1);
342-
p = zend_mempcpy(p, s2, len2);
343-
p = zend_mempcpy(p, s3, len3);
344-
*p = '\0';
345-
return res;
344+
char *res = (char *)safe_emalloc(len1, 1, len2 + len3 + 1);
345+
if (len1 > 0) {
346+
memcpy(res, s1, len1);
347+
}
348+
if (len2 > 0) {
349+
memcpy(res + len1, s2, len2);
350+
}
351+
if (len3 > 0) {
352+
memcpy(res + len1 + len2, s3, len3);
353+
}
354+
res[len1 + len2 + len3] = '\0';
355+
return res;
346356
}
347357

348358
static zend_always_inline void zend_string_free(zend_string *s)

0 commit comments

Comments
 (0)