Skip to content
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

ext/gmp: allow real number to create gmp int. #18254

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,20 @@ static zend_result convert_zstr_to_gmp(mpz_t gmp_number, const zend_string *val,
}
}

int gmp_ret = mpz_set_str(gmp_number, (skip_lead ? &num_str[2] : num_str), (int) base);
const char *nval = (skip_lead ? &num_str[2] : num_str);
int gmp_ret = mpz_set_str(gmp_number, nval, (int) base);
if (-1 == gmp_ret) {
if (arg_pos == 0) {
zend_value_error("Number is not an integer string");
} else {
zend_argument_value_error(arg_pos, "is not an integer string");
const char *err;
double dval = zend_strtod(nval, &err);
if (err == nval || *err != '\0') {
if (arg_pos == 0) {
zend_value_error("Number is not an integer string");
} else {
zend_argument_value_error(arg_pos, "is not an integer string");
}
return FAILURE;
}
return FAILURE;
mpz_set_d(gmp_number, dval);
}

return SUCCESS;
Expand Down
Loading