andrei          Tue Sep 10 14:34:17 2002 EDT

  Modified files:              
    /php4/ext/standard  array.c php_array.h 
  Log:
  @- Fixed array_merge_recursive() to avoid problems with merging cyclical
  @  arrays (bug #16064). (Andrei)
  
  
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.185 php4/ext/standard/array.c:1.186
--- php4/ext/standard/array.c:1.185     Mon Sep  9 16:05:20 2002
+++ php4/ext/standard/array.c   Tue Sep 10 14:34:16 2002
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.185 2002/09/09 20:05:20 andrei Exp $ */
+/* $Id: array.c,v 1.186 2002/09/10 18:34:16 andrei Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -1966,7 +1966,7 @@
 /* }}} */
 
 
-PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive)
+PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive)
 {
        zval      **src_entry,
                          **dest_entry;
@@ -1982,10 +1982,16 @@
                                if (recursive &&
                                        zend_hash_find(dest, string_key, 
string_key_len,
                                                                   (void 
**)&dest_entry) == SUCCESS) {
+                                       if (*src_entry == *dest_entry) {
+                                               zend_error(E_WARNING, "%s(): recursion 
+detected",
+                                                                  
+get_active_function_name());
+                                               return 0;
+                                       }
                                        convert_to_array_ex(dest_entry);
                                        convert_to_array_ex(src_entry);
-                                       php_array_merge(Z_ARRVAL_PP(dest_entry),
-                                                                       
Z_ARRVAL_PP(src_entry), recursive);
+                                       if (!php_array_merge(Z_ARRVAL_PP(dest_entry),
+                                                                       
+Z_ARRVAL_PP(src_entry), recursive))
+                                               return 0;
                                } else {
                                        (*src_entry)->refcount++;
 
@@ -2002,6 +2008,8 @@
 
                zend_hash_move_forward_ex(src, &pos);
        }
+
+       return 1;
 }
 
 static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive)
Index: php4/ext/standard/php_array.h
diff -u php4/ext/standard/php_array.h:1.35 php4/ext/standard/php_array.h:1.36
--- php4/ext/standard/php_array.h:1.35  Mon May 13 13:28:38 2002
+++ php4/ext/standard/php_array.h       Tue Sep 10 14:34:16 2002
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_array.h,v 1.35 2002/05/13 17:28:38 andrei Exp $ */
+/* $Id: php_array.h,v 1.36 2002/09/10 18:34:16 andrei Exp $ */
 
 #ifndef PHP_ARRAY_H
 #define PHP_ARRAY_H
@@ -83,7 +83,7 @@
 PHP_FUNCTION(array_chunk);
 
 HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
-PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive);
+PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive);
 int multisort_compare(const void *a, const void *b TSRMLS_DC);
 
 typedef struct {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to