-
Notifications
You must be signed in to change notification settings - Fork 7.8k
made scale argument of bcmath functions non-negative integer #5455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ebf7e7c
to
6dcbac8
Compare
6dcbac8
to
5fddc27
Compare
Can't add reviewers, so I'm just adding you to this message @nikic @kocsismate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Please address my inline comments.
Also, I think it is worthwhile to change bc_precision
to int
as well, and to introduce a custom validator, something like:
ext/bcmath/bcmath.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c
index 38fa4d033d..35d1bc92f6 100644
--- a/ext/bcmath/bcmath.c
+++ b/ext/bcmath/bcmath.c
@@ -57,9 +57,32 @@ ZEND_TSRMLS_CACHE_DEFINE()
ZEND_GET_MODULE(bcmath)
#endif
+ZEND_INI_MH(OnUpdateScale)
+{
+ int *p;
+ zend_long tmp;
+#ifndef ZTS
+ char *base = (char *) mh_arg2;
+#else
+ char *base;
+
+ base = (char *) ts_resource(*((int *) mh_arg2));
+#endif
+
+ tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
+ if (tmp < 0 || tmp > INT_MAX) {
+ return FAILURE;
+ }
+
+ p = (int *) (base+(size_t) mh_arg1);
+ *p = (int) tmp;
+
+ return SUCCESS;
+}
+
/* {{{ PHP_INI */
PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("bcmath.scale", "0", PHP_INI_ALL, OnUpdateLongGEZero, bc_precision, zend_bcmath_globals, bcmath_globals)
+ STD_PHP_INI_ENTRY("bcmath.scale", "0", PHP_INI_ALL, OnUpdateScale, bc_precision, zend_bcmath_globals, bcmath_globals)
PHP_INI_END()
/* }}} */
a20c9bd
to
263d335
Compare
Now the scale INI is not set. https://travis-ci.org/github/php/php-src/jobs/679741601#L2251 Can you help, to say what is wrong? |
Oh, sorry, my patch was incomplete. Need this as well: ext/bcmath/php_bcmath.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ext/bcmath/php_bcmath.h b/ext/bcmath/php_bcmath.h
index bafaf29e7a..c7a8a85d73 100644
--- a/ext/bcmath/php_bcmath.h
+++ b/ext/bcmath/php_bcmath.h
@@ -33,7 +33,7 @@ ZEND_BEGIN_MODULE_GLOBALS(bcmath)
bc_num _zero_;
bc_num _one_;
bc_num _two_;
- zend_long bc_precision;
+ int bc_precision;
ZEND_END_MODULE_GLOBALS(bcmath)
#if defined(ZTS) && defined(COMPILE_DL_BCMATH) |
263d335
to
0022353
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
- code styles (spaces -> tabs) - add custom ini setting validator (OnUpdateScale)
0022353
to
c167235
Compare
If you think I should make RFC, I will. From my POV it's just bugs and next (8) release can break things a little bit, so I'm making it more strict.
The only thing that bothers me is
ext/bcmath/tests/bug60377.phpt
. I did print out thebut it says
integer
. But internally it, somehow breaks and makes scale0
, this haven't worked before (I mean I haven't break the behavior where634314234334311
casts to0
) I have tried to do this before patchand got
0
.I may try to fix it, but I think