summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-04-23 19:05:16 +0200
committerNikita Popov <nikic@php.net>2014-04-23 19:34:51 +0200
commit08ae88157b4f73154b2f1ffe72c3957edb3772fc (patch)
treeb4c1ae6e553379588d5b214d01297d476de3e4a7 /ext
parent20580a511c029582fd2be6c8efbed40c89f7a874 (diff)
downloadphp-git-08ae88157b4f73154b2f1ffe72c3957edb3772fc.tar.gz
Allocate zend_strings with correct size
For me (32bit) sizeof(zend_string) is 20, which means that the char[1] array at the end is padded with three bytes. Thus allocating based on sizeof(zend_string)-1 overallocates by those 3 padding bytes. This commit fixes the allocation size, by using XtOffsetOf.
Diffstat (limited to 'ext')
-rw-r--r--ext/opcache/ZendAccelerator.c4
-rw-r--r--ext/opcache/zend_persist.c4
-rw-r--r--ext/opcache/zend_persist_calc.c2
-rw-r--r--ext/standard/php_smart_str.h4
-rw-r--r--ext/standard/tests/strings/str_pad_variation5.phpt2
5 files changed, 8 insertions, 8 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 84c397d7ab..11ca76e2f3 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -336,7 +336,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
idx = Z_NEXT(p->val);
}
- if (ZCSG(interned_strings_top) + ZEND_MM_ALIGNED_SIZE(sizeof(zend_string) + str->len) >=
+ if (ZCSG(interned_strings_top) + ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + str->len + 1) >=
ZCSG(interned_strings_end)) {
/* no memory, return the same non-interned string */
return str;
@@ -348,7 +348,7 @@ zend_string *accel_new_interned_string(zend_string *str TSRMLS_DC)
ZCSG(interned_strings).nNumOfElements++;
p = ZCSG(interned_strings).arData + idx;
p->key = (zend_string*) ZCSG(interned_strings_top);
- ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(sizeof(zend_string) + str->len);
+ ZCSG(interned_strings_top) += ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + str->len + 1);
p->h = h;
GC_REFCOUNT(p->key) = 1;
#if 1
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index ca2ad5150c..39a2aa4a7c 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -40,13 +40,13 @@
STR_RELEASE(str); \
str = new_str; \
} else { \
- new_str = _zend_shared_memdup((void*)str, sizeof(zend_string) + (str)->len, 0 TSRMLS_CC); \
+ new_str = _zend_shared_memdup((void*)str, _STR_HEADER_SIZE + (str)->len + 1, 0 TSRMLS_CC); \
STR_RELEASE(str); \
str = new_str; \
} \
} while (0)
# define zend_accel_memdup_string(str) \
- zend_accel_memdup(str, sizeof(zend_string) + (str)->len)
+ zend_accel_memdup(str, _STR_HEADER_SIZE + (str)->len + 1)
# define zend_accel_store_interned_string(str) do { \
if (!IS_ACCEL_INTERNED(str)) { \
zend_accel_store_string(str); \
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 6298fb1aa2..a347a34cf3 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -33,7 +33,7 @@
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
# define ADD_STRING(str) \
- ADD_DUP_SIZE((str), sizeof(zend_string) + (str)->len)
+ ADD_DUP_SIZE((str), _STR_HEADER_SIZE + (str)->len + 1)
# define ADD_INTERNED_STRING(str, do_free) do { \
if (!IS_ACCEL_INTERNED(str)) { \
zend_string *tmp = accel_new_interned_string(str TSRMLS_CC); \
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index a518fbfddf..5cc3a62137 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -45,11 +45,11 @@
#ifdef SMART_STR_USE_REALLOC
#define SMART_STR_DO_REALLOC(b, w) do { \
- (b)->s = erealloc((buf)->s, sizeof(zend_string) + (b)->a); \
+ (b)->s = erealloc((buf)->s, _STR_HEADER_SIZE + (b)->a + 1); \
} while (0)
#else
#define SMART_STR_DO_REALLOC(b, w) do { \
- (b)->s = perealloc((b)->s, sizeof(zend_string) + (b)->a, (w)); \
+ (b)->s = perealloc((b)->s, _STR_HEADER_SIZE + (b)->a + 1, (w)); \
} while (0)
#endif
diff --git a/ext/standard/tests/strings/str_pad_variation5.phpt b/ext/standard/tests/strings/str_pad_variation5.phpt
index 0dee148650..d050ae80e8 100644
--- a/ext/standard/tests/strings/str_pad_variation5.phpt
+++ b/ext/standard/tests/strings/str_pad_variation5.phpt
@@ -24,7 +24,7 @@ echo "*** Testing str_pad() function: with large value for for 'pad_length' argu
//defining '$input' argument
$input = "Test string";
-$pad_length = PHP_INT_MAX - 20 + 1; /* sizeof(zend_string) is 20, 1 character is included in zend_string structure itself */
+$pad_length = PHP_INT_MAX - 16; /* zend_string header is 16 bytes */
var_dump( str_pad($input, $pad_length) );
?>