Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ PHPAPI zend_long _php_math_basetolong(zval *arg, int base)
/*
* Convert a string representation of a base(2-36) number to a zval.
*/
PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
PHPAPI zend_result _php_math_basetozval(zend_string *str, int base, zval *ret)
{
zend_long num = 0;
double fnum = 0;
Expand Down Expand Up @@ -908,14 +908,16 @@ PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
}

if (invalidchars > 0) {
zend_error(E_DEPRECATED, "Invalid characters passed for attempted conversion, these have been ignored");
zend_value_error("Invalid characters passed for attempted conversion");
return FAILURE;
}

if (mode == 1) {
ZVAL_DOUBLE(ret, fnum);
} else {
ZVAL_LONG(ret, num);
}
return SUCCESS;
}
/* }}} */

Expand Down Expand Up @@ -1033,7 +1035,9 @@ PHP_FUNCTION(bindec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 2, return_value);
if (SUCCESS != _php_math_basetozval(arg, 2, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand All @@ -1046,7 +1050,9 @@ PHP_FUNCTION(hexdec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 16, return_value);
if (SUCCESS != _php_math_basetozval(arg, 16, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand All @@ -1059,7 +1065,9 @@ PHP_FUNCTION(octdec)
Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();

_php_math_basetozval(arg, 8, return_value);
if (SUCCESS != _php_math_basetozval(arg, 8, return_value)) {
RETURN_THROWS();
}
}
/* }}} */

Expand Down Expand Up @@ -1136,7 +1144,10 @@ PHP_FUNCTION(base_convert)
RETURN_THROWS();
}

_php_math_basetozval(number, (int)frombase, &temp);
if (SUCCESS != _php_math_basetozval(number, (int)frombase, &temp)) {
RETURN_THROWS();
}

result = _php_math_zvaltobase(&temp, (int)tobase);
if (!result) {
RETURN_THROWS();
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/php_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, const char *de
PHPAPI zend_string *_php_math_number_format_long(zend_long num, zend_long dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len);
PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base);
PHPAPI zend_long _php_math_basetolong(zval *arg, int base);
PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret);
PHPAPI zend_result _php_math_basetozval(zend_string *str, int base, zval *ret);
PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base);

#include <math.h>
Expand Down
Loading
Loading