Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Zend/zend_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@
#include "zend_gc.h"
#include "zend_alloc.h"

#include "zend_errors.h"

BEGIN_EXTERN_C()

ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

#include "zend_multiply.h"

typedef void (*zend_string_copy_storage_func_t)(void);
typedef zend_string *(ZEND_FASTCALL *zend_new_interned_string_func_t)(zend_string *str);
typedef zend_string *(ZEND_FASTCALL *zend_string_init_interned_func_t)(const char *str, size_t size, bool permanent);
Expand Down Expand Up @@ -316,6 +322,48 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
return ret;
}

static zend_always_inline char *zend_cstr_append_char(const char *str, size_t len, char c) {
char *res = (char *)safe_emalloc(len, 1, 2);
if (len > 0) {
memcpy(res, str, len);
}
res[len] = c;
res[len + 1] = '\0';
return res;
}

static zend_always_inline char *zend_cstr_concat(const char *s1, size_t len1, const char *s2, size_t len2) {
size_t size = zend_safe_address_guarded(1, len1, len2);
size = zend_safe_address_guarded(1, size, 1);
char *res = (char *)emalloc(size);
if (len1 > 0) {
memcpy(res, s1, len1);
}
if (len2 > 0) {
memcpy(res + len1, s2, len2);
}
res[len1 + len2] = '\0';
return res;
}

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) {
size_t size = zend_safe_address_guarded(1, len1, len2);
size = zend_safe_address_guarded(1, size, len3);
size = zend_safe_address_guarded(1, size, 1);
char *res = (char *)emalloc(size);
if (len1 > 0) {
memcpy(res, s1, len1);
}
if (len2 > 0) {
memcpy(res + len1, s2, len2);
}
if (len3 > 0) {
memcpy(res + len1 + len2, s3, len3);
}
res[len1 + len2 + len3] = '\0';
return res;
}

static zend_always_inline void zend_string_free(zend_string *s)
{
if (!ZSTR_IS_INTERNED(s)) {
Expand Down
Loading