com php-src: Don't double initialize object properties: Zend/zend_objects.c

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    3abef9c9609eef04f268e1fd002e6ca7edac11fa
Author:    Nikita Popov <[email protected]>         Tue, 2 May 2017 22:16:41 +0200
Parents:   9d6b7435e4fc0f84096164e91c5aade1cfe1ac96
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=3abef9c9609eef04f268e1fd002e6ca7edac11fa

Log:
Don't double initialize object properties

Changed paths:
  M  Zend/zend_objects.c


Diff:
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c
index 9b5a2c7..900ec1d 100644
--- a/Zend/zend_objects.c
+++ b/Zend/zend_objects.c
@@ -36,17 +36,9 @@ ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce)
 	object->ce = ce;
 	object->properties = NULL;
 	zend_objects_store_put(object);
-	p = object->properties_table;
-	if (EXPECTED(ce->default_properties_count != 0)) {
-		end = p + ce->default_properties_count;
-		do {
-			ZVAL_UNDEF(p);
-			p++;
-		} while (p != end);
-	}
 	if (UNEXPECTED(ce->ce_flags & ZEND_ACC_USE_GUARDS)) {
 		GC_FLAGS(object) |= IS_OBJ_USE_GUARDS;
-		ZVAL_UNDEF(p);
+		ZVAL_UNDEF(object->properties_table + object->ce->default_properties_count);
 	}
 }
 
@@ -252,6 +244,16 @@ ZEND_API zend_object *zend_objects_clone_obj(zval *zobject)
 	old_object = Z_OBJ_P(zobject);
 	new_object = zend_objects_new(old_object->ce);
 
+	/* zend_objects_clone_members() expect the properties to be initialized. */
+	if (new_object->ce->default_properties_count) {
+		zval *p = new_object->properties_table;
+		zval *end = p + new_object->ce->default_properties_count;
+		do {
+			ZVAL_UNDEF(p);
+			p++;
+		} while (p != end);
+	}
+
 	zend_objects_clone_members(new_object, old_object);
 
 	return new_object;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.