Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
To allow us to do this: $a = array('a' = 1, 'b' = 2); $b = $a; $c = $a; array_merge_recursive($b, $c); The old check has a problem, because $b $c are write only copies *src_entry == *dest_entry condition is met and the function incorrectly terminates claiming a circular reference. We cannot use is_ref field to verify references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Ilia On June 17, 2003 10:06 am, Andrei Zmievski wrote: On Mon, 16 Jun 2003, Ilia Alshanetsky wrote: + if (*src_entry == *dest_entry ((*dest_entry)-refcount % 2)) { Why this %2 test? -Andrei For every complex problem, there is a solution that is simple, neat, and wrong. -- H. L. Mencken -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
On Tue, Jun 17, 2003 at 10:24:46AM -0400, Ilia A. wrote: The old check has a problem, because $b $c are write only copies *src_entry == *dest_entry condition is met and the function incorrectly terminates claiming a circular reference. We cannot use is_ref field to verify references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Golly, that sounds like a swell thing to document alongside of the code. -- Jon Parise ([EMAIL PROTECTED]) :: The PHP Project (http://www.php.net/) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
On Tue, 17 Jun 2003, Ilia A. wrote: references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Can you explain the rationality behind this property? Why can't we have is_ref=0 and refcount=3? -Andrei * All of the above is my opinion, unless specified otherwise. * -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
iliaa Mon Jun 16 13:35:16 2003 EDT Added files: /php4/ext/standard/tests/array bug24198.phpt Modified files: /php4/ext/standard array.c Log: Fixed bug #24198 (Invalid recursion detection in array_merge_recurcive()) Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.233 php4/ext/standard/array.c:1.234 --- php4/ext/standard/array.c:1.233 Thu Jun 12 11:11:11 2003 +++ php4/ext/standard/array.c Mon Jun 16 13:35:16 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.233 2003/06/12 15:11:11 andrey Exp $ */ +/* $Id: array.c,v 1.234 2003/06/16 17:35:16 iliaa Exp $ */ #include php.h #include php_ini.h @@ -2141,7 +2141,7 @@ case HASH_KEY_IS_STRING: if (recursive zend_hash_find(dest, string_key, string_key_len, (void **)dest_entry) == SUCCESS) { - if (*src_entry == *dest_entry) { + if (*src_entry == *dest_entry ((*dest_entry)-refcount % 2)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, recursion detected); return 0; } Index: php4/ext/standard/tests/array/bug24198.phpt +++ php4/ext/standard/tests/array/bug24198.phpt --TEST--n Bug #24198 (array_merge_recursive() invalid recursion detection) --FILE-- ?php $c = array('a' = 'aa','b' = 'bb'); var_dump(array_merge_recursive($c, $c)); ? --EXPECT-- array(2) { [a]= array(2) { [0]= string(2) aa [1]= string(2) aa } [b]= array(2) { [0]= string(2) bb [1]= string(2) bb } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php