From 4859431fc11cd89ac09ab4e9e4e6be49a6d0a75e Mon Sep 17 00:00:00 2001 From: Moriyoshi Koizumi Date: Fri, 3 Oct 2003 22:41:43 +0000 Subject: [PATCH] Fixed bug #24766 (strange result array from unpack()) --- Zend/zend_API.c | 20 ++++++++-------- ext/standard/tests/array/bug24766.phpt | 32 ++++++++++++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index b616b2fca7c..edba59c2eb2 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -745,7 +745,7 @@ ZEND_API int add_assoc_long_ex(zval *arg, char *key, uint key_len, long n) MAKE_STD_ZVAL(tmp); ZVAL_LONG(tmp, n); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } ZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len) @@ -755,7 +755,7 @@ ZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len) MAKE_STD_ZVAL(tmp); ZVAL_NULL(tmp); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } ZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b) @@ -765,7 +765,7 @@ ZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b) MAKE_STD_ZVAL(tmp); ZVAL_BOOL(tmp, b); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } ZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r) @@ -775,7 +775,7 @@ ZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r) MAKE_STD_ZVAL(tmp); ZVAL_RESOURCE(tmp, r); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } @@ -786,7 +786,7 @@ ZEND_API int add_assoc_double_ex(zval *arg, char *key, uint key_len, double d) MAKE_STD_ZVAL(tmp); ZVAL_DOUBLE(tmp, d); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } @@ -797,7 +797,7 @@ ZEND_API int add_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, MAKE_STD_ZVAL(tmp); ZVAL_STRING(tmp, str, duplicate); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } @@ -808,12 +808,12 @@ ZEND_API int add_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, MAKE_STD_ZVAL(tmp); ZVAL_STRINGL(tmp, str, length, duplicate); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL); } ZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value) { - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL); } @@ -989,7 +989,7 @@ ZEND_API int add_get_assoc_string_ex(zval *arg, char *key, uint key_len, char *s MAKE_STD_ZVAL(tmp); ZVAL_STRING(tmp, str, duplicate); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest); } @@ -1000,7 +1000,7 @@ ZEND_API int add_get_assoc_stringl_ex(zval *arg, char *key, uint key_len, char * MAKE_STD_ZVAL(tmp); ZVAL_STRINGL(tmp, str, length, duplicate); - return zend_hash_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest); + return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest); } diff --git a/ext/standard/tests/array/bug24766.phpt b/ext/standard/tests/array/bug24766.phpt index 89434c19394..d6f82f3b16f 100644 --- a/ext/standard/tests/array/bug24766.phpt +++ b/ext/standard/tests/array/bug24766.phpt @@ -5,15 +5,16 @@ Bug #24766 (strange result array from unpack) error_reporting(E_ALL); -$a=unpack('C2', "\0224V"); -debug_zval_dump($a); -$k=array_keys($a); -debug_zval_dump($k); - +$a = unpack('C2', "\0224V"); +$b = array(1 => 18, 2 => 52); +debug_zval_dump($a, $b); +$k = array_keys($a); +$l = array_keys($b); +debug_zval_dump($k, $l); $i=$k[0]; - -echo $a[$i],"\n"; - +var_dump($a[$i]); +$i=$l[0]; +var_dump($b[$i]); ?> --EXPECT-- array(2) refcount(2){ @@ -22,10 +23,23 @@ array(2) refcount(2){ [2]=> long(52) refcount(1) } +array(2) refcount(2){ + [1]=> + long(18) refcount(1) + [2]=> + long(52) refcount(1) +} array(2) refcount(2){ [0]=> long(1) refcount(1) [1]=> long(2) refcount(1) } -18 +array(2) refcount(2){ + [0]=> + long(1) refcount(1) + [1]=> + long(2) refcount(1) +} +int(18) +int(18)