From 55b553c1ef4f17453b73ba3d205baf395f1d03da Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 30 Aug 2024 20:59:45 +0900 Subject: [PATCH 1/3] Added a test case operator overloading --- ext/gmp/tests/overloading.phpt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/gmp/tests/overloading.phpt b/ext/gmp/tests/overloading.phpt index 14c35ea8470c3..3a5f6c53e9073 100644 --- a/ext/gmp/tests/overloading.phpt +++ b/ext/gmp/tests/overloading.phpt @@ -11,6 +11,7 @@ $b = gmp_init(17); var_dump($a + $b); var_dump($a + 17); var_dump(42 + $b); +var_dump($a + null); var_dump($a - $b); var_dump($a - 17); @@ -136,6 +137,10 @@ object(GMP)#3 (1) { ["num"]=> string(2) "59" } +object(GMP)#3 (1) { + ["num"]=> + string(2) "42" +} object(GMP)#3 (1) { ["num"]=> string(2) "25" From 02a9228169bb01633ea2a0694bc272e89b52a2b0 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 30 Aug 2024 23:26:47 +0900 Subject: [PATCH 2/3] Added null case to gmp_zval_binary_ui_op --- ext/gmp/gmp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 02eb30bacb730..51e2792a77d3a 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -707,12 +707,22 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval * mpz_ptr gmpnum_a, gmpnum_b, gmpnum_result; gmp_temp_t temp_a, temp_b; + if (UNEXPECTED(is_operator && Z_TYPE_P(a_arg) == IS_NULL)) { + zval a_arg_2; + ZVAL_LONG(&a_arg_2, 0); + a_arg = &a_arg_2; + } FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a, is_operator ? 0 : 1); if (gmp_ui_op && Z_TYPE_P(b_arg) == IS_LONG && Z_LVAL_P(b_arg) >= 0) { gmpnum_b = NULL; temp_b.is_used = 0; } else { + if (UNEXPECTED(is_operator && Z_TYPE_P(b_arg) == IS_NULL)) { + zval b_arg_2; + ZVAL_LONG(&b_arg_2, 0); + b_arg = &b_arg_2; + } FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a, is_operator ? 0 : 2); } From aff49646c4d648951139424c7e547b4625e59a9d Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:52:54 +0900 Subject: [PATCH 3/3] fixed zval place --- ext/gmp/gmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 51e2792a77d3a..9ada4996900a1 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -707,8 +707,8 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval * mpz_ptr gmpnum_a, gmpnum_b, gmpnum_result; gmp_temp_t temp_a, temp_b; + zval a_arg_2; if (UNEXPECTED(is_operator && Z_TYPE_P(a_arg) == IS_NULL)) { - zval a_arg_2; ZVAL_LONG(&a_arg_2, 0); a_arg = &a_arg_2; } @@ -718,8 +718,8 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval * gmpnum_b = NULL; temp_b.is_used = 0; } else { + zval b_arg_2; if (UNEXPECTED(is_operator && Z_TYPE_P(b_arg) == IS_NULL)) { - zval b_arg_2; ZVAL_LONG(&b_arg_2, 0); b_arg = &b_arg_2; }