]> granicus.if.org Git - php/commitdiff
fixed trim() and strtok() to work with big strings
authorAnatol Belski <ab@php.net>
Thu, 28 Aug 2014 19:59:00 +0000 (21:59 +0200)
committerAnatol Belski <ab@php.net>
Thu, 28 Aug 2014 19:59:00 +0000 (21:59 +0200)
Zend/zend_execute.c
ext/standard/string.c

index d3d01797d766e975720a48cff37889ecfad02f99..57e68a2d5392cfda0399ccdbcdbbc9a562930dca 100644 (file)
@@ -759,11 +759,14 @@ static inline void zend_assign_to_object(zval *retval, zval *object_ptr, zval *p
 static void zend_assign_to_string_offset(zval *str_offset, zval *value, int value_type, zval *result TSRMLS_DC)
 {
        zval *str = Z_STR_OFFSET_STR_P(str_offset);
-       uint32_t offset = Z_STR_OFFSET_IDX_P(str_offset);
+       /* XXX String offset is uint32_t in _zval_struct, so can address only 2^32+1 space.
+               To make the offset get over that barier, we need to make str_offset size_t and that
+               would grow zval size by 8 bytes (currently from 16 to 24) on 64 bit build. */
+       size_t offset = (size_t)Z_STR_OFFSET_IDX_P(str_offset);
        zend_string *old_str;
 
-       if ((int)offset < 0) {
-               zend_error(E_WARNING, "Illegal string offset:  %d", offset);
+       if ((zend_long)offset < 0) {
+               zend_error(E_WARNING, "Illegal string offset:  %zd", offset);
                zend_string_release(Z_STR_P(str));
                if (result) {
                        ZVAL_NULL(result);
@@ -773,7 +776,7 @@ static void zend_assign_to_string_offset(zval *str_offset, zval *value, int valu
 
        old_str = Z_STR_P(str);
        if (offset >= Z_STRLEN_P(str)) {
-               int old_len = Z_STRLEN_P(str);
+               size_t old_len = Z_STRLEN_P(str);
                Z_STR_P(str) = zend_string_realloc(Z_STR_P(str), offset + 1, 0);
                Z_TYPE_INFO_P(str) = IS_STRING_EX;
                memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
index a37b858b2f13a5fabfa809bcfe51f883a04dd4de..a85a73fe6a8df44363c58671b0e656dbe0d6f4f6 100644 (file)
@@ -781,7 +781,7 @@ static inline int php_charmask(unsigned char *input, size_t len, char *mask TSRM
 PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *return_value, int mode TSRMLS_DC)
 {
        register zend_long i;
-       int trimmed = 0;
+       size_t trimmed = 0;
        char mask[256];
 
        if (what) {
@@ -1257,7 +1257,7 @@ PHP_FUNCTION(strtok)
        char *token_end;
        char *p;
        char *pe;
-       int skipped = 0;
+       size_t skipped = 0;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &tok) == FAILURE) {
                return;
@@ -1465,7 +1465,7 @@ quit_loop:
        if (state == 1) {
                cend = c;
        }
-       if (suffix != NULL && sufflen < (uint)(cend - comp) &&
+       if (suffix != NULL && sufflen < (size_t)(cend - comp) &&
                        memcmp(cend - sufflen, suffix, sufflen) == 0) {
                cend -= sufflen;
        }
@@ -1554,7 +1554,7 @@ PHP_FUNCTION(pathinfo)
 
        if ((opt & PHP_PATHINFO_EXTENSION) == PHP_PATHINFO_EXTENSION) {
                const char *p;
-               int idx;
+               ptrdiff_t idx;
 
                if (!have_basename) {
                        ret = php_basename(path, path_len, NULL, 0 TSRMLS_CC);
@@ -1570,7 +1570,7 @@ PHP_FUNCTION(pathinfo)
 
        if ((opt & PHP_PATHINFO_FILENAME) == PHP_PATHINFO_FILENAME) {
                const char *p;
-               int idx;
+               ptrdiff_t idx;
 
                /* Have we already looked up the basename? */
                if (!have_basename && !ret) {