ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
int length = Z_STRLEN_P(op1) + 1;
- char *buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
+ char *buf;
+
+ if (UNEXPECTED(length < 0)) {
+ zend_error(E_ERROR, "String size overflow");
+ }
+
- if (IS_INTERNED(Z_STRVAL_P(op1))) {
- buf = (char *) emalloc(length + 1);
- memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
- } else {
- buf = (char *) erealloc(Z_STRVAL_P(op1), length + 1);
- }
++ buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
+
buf[length - 1] = (char) Z_LVAL_P(op2);
buf[length] = 0;
ZVAL_STRINGL(result, buf, length, 0);
ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2) /* {{{ */
{
int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
- char *buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
+ char *buf;
+
+ if (UNEXPECTED(length < 0)) {
+ zend_error(E_ERROR, "String size overflow");
+ }
- if (IS_INTERNED(Z_STRVAL_P(op1))) {
- buf = (char *) emalloc(length+1);
- memcpy(buf, Z_STRVAL_P(op1), Z_STRLEN_P(op1));
- } else {
- buf = (char *) erealloc(Z_STRVAL_P(op1), length+1);
- }
++
++ buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
+
memcpy(buf + Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
buf[length] = 0;
ZVAL_STRINGL(result, buf, length, 0);