fixed trim() and strtok() to work with big strings

This commit is contained in:
Anatol Belski 2014-08-28 21:59:00 +02:00
parent 8e05b9104b
commit 898e1570a2
2 changed files with 12 additions and 9 deletions

View 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);

View 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) {