]> granicus.if.org Git - php/commitdiff
Review a few more SEPARATE_ZVAL_IF_NOT_REF usages
authorNikita Popov <nikic@php.net>
Thu, 9 Oct 2014 10:51:05 +0000 (12:51 +0200)
committerNikita Popov <nikic@php.net>
Thu, 9 Oct 2014 10:51:05 +0000 (12:51 +0200)
Zend/zend_execute_API.c
Zend/zend_types.h
ext/filter/filter.c
ext/filter/tests/filter_var_array_with_ref.phpt [new file with mode: 0644]
ext/mbstring/php_mbregex.c
ext/session/session.c
ext/spl/spl_array.c

index f6bd9d1ca70494249e95451b50bda6402a076a5a..cd2cc98b42a072a813e1501f3c727bf2d355bc0e 100644 (file)
@@ -521,7 +521,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
        } else if (Z_TYPE_P(p) == IS_CONSTANT) {
                int refcount;
 
-               SEPARATE_ZVAL_IF_NOT_REF(p);
+               SEPARATE_ZVAL_NOREF(p);
                MARK_CONSTANT_VISITED(p);
                refcount =  Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
                const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p) TSRMLS_CC);
@@ -599,7 +599,7 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
                if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
        } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) {
                zval tmp;
-               SEPARATE_ZVAL_IF_NOT_REF(p);
+               SEPARATE_ZVAL_NOREF(p);
 
                zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope TSRMLS_CC);
                if (inline_change) {
index b7e806804f2eec8b11ed1c6bf92e1c0e4c2fd506..811133a27515d0fda283108d208b767af5f934d7 100644 (file)
@@ -783,6 +783,7 @@ static zend_always_inline uint32_t zval_delref_p(zval* pz) {
 
 #define SEPARATE_ZVAL_NOREF(zv) do {                                   \
                zval *_zv = (zv);                                                               \
+               ZEND_ASSERT(Z_TYPE_P(_zv) != IS_REFERENCE);             \
                if (Z_COPYABLE_P(_zv) ||                                                \
                    Z_IMMUTABLE_P(_zv)) {                                               \
                        if (Z_REFCOUNT_P(_zv) > 1) {                            \
index 7ef65bc196764798857fc600f688cdadff7cea1e..ec3c007afd8f2b3ca534133c55580e71e45d4b6f 100644 (file)
@@ -491,7 +491,8 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f
                }
 
                ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(value), element) {
-                       SEPARATE_ZVAL_IF_NOT_REF(element);
+                       ZVAL_DEREF(element);
+                       SEPARATE_ZVAL_NOREF(element);
                        if (Z_TYPE_P(element) == IS_ARRAY) {
                                Z_ARRVAL_P(element)->u.v.nApplyCount++;
                                php_zval_filter_recursive(element, filter, flags, options, charset, copy TSRMLS_CC);
diff --git a/ext/filter/tests/filter_var_array_with_ref.phpt b/ext/filter/tests/filter_var_array_with_ref.phpt
new file mode 100644 (file)
index 0000000..cd202ed
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+filter_var_array() on array with reference
+--FILE--
+<?php
+
+$array = ["123foo"];
+$array2 = [&$array];
+var_dump(filter_var_array($array2, FILTER_VALIDATE_INT));
+var_dump($array);
+
+?>
+--EXPECTF--
+array(1) {
+  [0]=>
+  &array(1) {
+    [0]=>
+    bool(false)
+  }
+}
+array(1) {
+  [0]=>
+  bool(false)
+}
index de0bc768ad383b0147f709d51ac8dee408b232ea..8be88c3fee3f8def400e1627e4e5bdc22c515807 100644 (file)
@@ -1343,8 +1343,7 @@ PHP_FUNCTION(mb_ereg_search_init)
                zval_ptr_dtor(&MBREX(search_str));
        }
 
-       ZVAL_COPY(&MBREX(search_str), arg_str);
-       SEPARATE_ZVAL_IF_NOT_REF(&MBREX(search_str));
+       ZVAL_DUP(&MBREX(search_str), arg_str);
 
        MBREX(search_pos) = 0;
 
index 63bb00e06a56b4e0e56bd4979c51982e8d75ac95..dae965b048145b272264de300e724f87233e1da2 100644 (file)
@@ -2105,10 +2105,7 @@ static PHP_FUNCTION(session_unset)
        }
 
        IF_SESSION_VARS() {
-               HashTable *ht_sess_var;
-
-               SEPARATE_ZVAL_IF_NOT_REF(&PS(http_session_vars));
-               ht_sess_var = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars)));
+               HashTable *ht_sess_var = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars)));
 
                /* Clean $_SESSION. */
                zend_hash_clean(ht_sess_var);
index 211180a08dc285cbb8aa32671a8865473f9f2f8e..8aab4c49bfa6af3e2cc300542524f6fba24b9048 100644 (file)
@@ -1144,7 +1144,7 @@ static void spl_array_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
 static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, int just_array TSRMLS_DC) {
 
        if (Z_TYPE_P(array) == IS_ARRAY) {
-               SEPARATE_ZVAL_IF_NOT_REF(array);
+               SEPARATE_ARRAY(array);
        }
 
        if (Z_TYPE_P(array) == IS_OBJECT && (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator)) {