]> granicus.if.org Git - php/commitdiff
Throw "Unsupported operand types" error when using ** on arrays
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Oct 2019 12:05:02 +0000 (13:05 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 29 Oct 2019 12:05:02 +0000 (13:05 +0100)
Zend/tests/bug74084.phpt
Zend/tests/pow_array_leak.phpt
Zend/zend_operators.c
ext/standard/tests/math/pow_variation1.phpt
ext/standard/tests/math/pow_variation1_64bit.phpt
ext/standard/tests/math/pow_variation2.phpt

index 108f03be366c4e4f104d8409d852f569a40a35f6..ab4dce0a5a315087bddde16dc946db1f01b8ce52 100644 (file)
@@ -24,11 +24,14 @@ try {
     echo $e->getMessage(), "\n";
 }
 unset($$A);
-$$A **= $$B['a'] = &$$C;
-var_dump($$A);
+try {
+    $$A **= $$B['a'] = &$$C;
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECT--
 Unsupported operand types
 Unsupported operand types
 Unsupported operand types
-int(0)
+Unsupported operand types
index e9165bbbc569cfd2dc57bbae5132256dab164dcc..a17a290458385d1dece0ee70ff54a0acdbdb421c 100644 (file)
@@ -4,14 +4,30 @@ Memory leak on ** with result==op1 array
 <?php
 
 $x = [0];
-$x **= 1;
+try {
+    $x **= 1;
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
 var_dump($x);
 
 $x = [0];
-$x **= $x;
+try {
+    $x **= $x;
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
 var_dump($x);
 
 ?>
 --EXPECT--
-int(0)
-int(0)
+Unsupported operand types
+array(1) {
+  [0]=>
+  int(0)
+}
+Unsupported operand types
+array(1) {
+  [0]=>
+  int(0)
+}
index 69ee522b4c36fdca6f3aa92138e617fc73b77342..a1f3024d4e9ba21dd566ef804e541e211eae49a6 100644 (file)
@@ -1197,37 +1197,22 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
                        } else if (!converted) {
                                ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_POW, pow_function);
 
-                               if (EXPECTED(op1 != op2)) {
-                                       if (Z_TYPE_P(op1) == IS_ARRAY) {
-                                               if (op1 == result) {
-                                                       zval_ptr_dtor(result);
-                                               }
-                                               ZVAL_LONG(result, 0);
-                                               return SUCCESS;
-                                       } else {
-                                               op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
-                                       }
-                                       if (Z_TYPE_P(op2) == IS_ARRAY) {
-                                               if (op1 == result) {
-                                                       zval_ptr_dtor(result);
-                                               }
-                                               ZVAL_LONG(result, 1L);
-                                               return SUCCESS;
-                                       } else {
-                                               op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
+                               if (Z_TYPE_P(op1) == IS_ARRAY || Z_TYPE_P(op2) == IS_ARRAY) {
+                                       if (result != op1) {
+                                               ZVAL_UNDEF(result);
                                        }
+                                       zend_throw_error(NULL, "Unsupported operand types");
+                                       return FAILURE;
+                               }
+
+                               if (EXPECTED(op1 != op2)) {
+                                       op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
+                                       op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
                                } else {
-                                       if (Z_TYPE_P(op1) == IS_ARRAY) {
-                                               if (op1 == result) {
-                                                       zval_ptr_dtor(result);
-                                               }
-                                               ZVAL_LONG(result, 0);
-                                               return SUCCESS;
-                                       } else {
-                                               op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
-                                       }
+                                       op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
                                        op2 = op1;
                                }
+
                                if (EG(exception)) {
                                        if (result != op1) {
                                                ZVAL_UNDEF(result);
index a3e13d861c75e6b2936da074c2b75bc7856c4e05..86df8e0eb4be9936489affb9e688cb8b14dfe673 100644 (file)
@@ -84,9 +84,13 @@ $inputs = array(
 // loop through each element of $inputs to check the behaviour of pow()
 $iterator = 1;
 foreach($inputs as $input) {
-       echo "\n-- Iteration $iterator --\n";
-       var_dump(pow($input, 3));
-       $iterator++;
+    echo "\n-- Iteration $iterator --\n";
+    try {
+        var_dump(pow($input, 3));
+    } catch (Error $e) {
+        echo $e->getMessage(), "\n";
+    }
+    $iterator++;
 };
 fclose($fp);
 ?>
@@ -153,7 +157,7 @@ Warning: A non-numeric value encountered in %s on line %d
 int(0)
 
 -- Iteration 19 --
-int(0)
+Unsupported operand types
 
 -- Iteration 20 --
 
index 0d8b1960be382bc4de4ff422336bd1911b01606d..da63ae3d9f070d322535b873fa6fb09f11344875 100644 (file)
@@ -84,9 +84,13 @@ $inputs = array(
 // loop through each element of $inputs to check the behaviour of pow()
 $iterator = 1;
 foreach($inputs as $input) {
-       echo "\n-- Iteration $iterator --\n";
-       var_dump(pow($input, 3));
-       $iterator++;
+    echo "\n-- Iteration $iterator --\n";
+    try {
+        var_dump(pow($input, 3));
+    } catch (Error $e) {
+        echo $e->getMessage(), "\n";
+    }
+    $iterator++;
 };
 fclose($fp);
 ?>
@@ -153,7 +157,7 @@ Warning: A non-numeric value encountered in %s on line %d
 int(0)
 
 -- Iteration 19 --
-int(0)
+Unsupported operand types
 
 -- Iteration 20 --
 
index 4876447da9ceff10bd3429d745fd7bdb08882293..83d1fda06526e8a651a14d655c7a56979149f736 100644 (file)
@@ -80,9 +80,13 @@ $inputs = array(
 // loop through each element of $inputs to check the behaviour of pow()
 $iterator = 1;
 foreach($inputs as $input) {
-       echo "\n-- Iteration $iterator --\n";
-       var_dump(pow(20.3, $input));
-       $iterator++;
+    echo "\n-- Iteration $iterator --\n";
+    try {
+        var_dump(pow(20.3, $input));
+    } catch (Error $e) {
+        echo $e->getMessage(), "\n";
+    }
+    $iterator++;
 };
 fclose($fp);
 ?>
@@ -149,7 +153,7 @@ Warning: A non-numeric value encountered in %s on line %d
 float(1)
 
 -- Iteration 19 --
-int(1)
+Unsupported operand types
 
 -- Iteration 20 --