]> granicus.if.org Git - php/commitdiff
More accurate zval comparison
authorDmitry Stogov <dmitry@zend.com>
Wed, 19 Mar 2014 18:43:36 +0000 (22:43 +0400)
committerDmitry Stogov <dmitry@zend.com>
Wed, 19 Mar 2014 18:43:36 +0000 (22:43 +0400)
Zend/zend_API.c

index a9c10b6c324fd3b061436af42d3255560c6bf4c2..e9d30811db7a42c573f7795187aa784424b9f857 100644 (file)
@@ -3931,12 +3931,37 @@ ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling,
 }
 /* }}} */
 
+static int same_zval(zval *zv1, zval *zv2)  /* {{{ */
+{
+       if (Z_TYPE_P(zv1) != Z_TYPE_P(zv2)) {
+               return 0;
+       }
+       switch (Z_TYPE_P(zv1)) {
+               case IS_UNDEF:
+               case IS_NULL:
+                       return 1;
+               case IS_BOOL:
+               case IS_LONG:
+                       return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
+               case IS_DOUBLE:
+                       return Z_LVAL_P(zv1) == Z_LVAL_P(zv2);
+               case IS_STRING:
+               case IS_ARRAY:
+               case IS_OBJECT:
+               case IS_RESOURCE:
+                       return Z_COUNTED_P(zv1) == Z_COUNTED_P(zv2);
+               default:
+                       return 0;
+       }
+}
+/* }}} */
+
 ZEND_API void zend_restore_error_handling(zend_error_handling *saved TSRMLS_DC) /* {{{ */
 {
        EG(error_handling) = saved->handling;
        EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
        if (Z_TYPE(saved->user_handler) != IS_UNDEF
-               && memcmp(&saved->user_handler, &EG(user_error_handler), sizeof(zval)) != 0) {
+               && !same_zval(&saved->user_handler, &EG(user_error_handler))) {
                zval_ptr_dtor(&EG(user_error_handler));
                ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
        } else if (Z_TYPE(saved->user_handler)) {