mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
Throw warning when converting invalid string to GMP
This commit is contained in:
parent
feb4caad09
commit
5408f1e5a6
@ -718,14 +718,14 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
|
||||
{
|
||||
switch (Z_TYPE_P(val)) {
|
||||
case IS_LONG:
|
||||
case IS_BOOL:
|
||||
case IS_CONSTANT: {
|
||||
case IS_BOOL: {
|
||||
mpz_set_si(gmpnumber, gmp_get_long(val));
|
||||
return SUCCESS;
|
||||
}
|
||||
case IS_STRING: {
|
||||
char *numstr = Z_STRVAL_P(val);
|
||||
int skip_lead = 0;
|
||||
int ret;
|
||||
|
||||
if (Z_STRLEN_P(val) > 2) {
|
||||
if (numstr[0] == '0') {
|
||||
@ -739,10 +739,18 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
|
||||
}
|
||||
}
|
||||
|
||||
return mpz_set_str(gmpnumber, (skip_lead ? &numstr[2] : numstr), base);
|
||||
ret = mpz_set_str(gmpnumber, (skip_lead ? &numstr[2] : numstr), base);
|
||||
if (-1 == ret) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
||||
"Unable to convert variable to GMP - string is not an integer");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
default:
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert variable to GMP - wrong type");
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
||||
"Unable to convert variable to GMP - wrong type");
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ Check for number base recognition
|
||||
printf("%s\n", gmp_strval($test[$i]));
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
1234
|
||||
1234
|
||||
10011010010
|
||||
|
@ -36,6 +36,8 @@ echo "Done\n";
|
||||
--EXPECTF--
|
||||
Warning: gmp_strval() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: gmp_strval(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_strval() expects parameter 2 to be long, string given in %s on line %d
|
||||
|
@ -28,6 +28,8 @@ NULL
|
||||
|
||||
Warning: gmp_sub() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: gmp_sub(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_sub() expects exactly 2 parameters, 3 given in %s on line %d
|
||||
|
@ -27,6 +27,8 @@ NULL
|
||||
|
||||
Warning: gmp_mod() expects exactly 2 parameters, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: gmp_mod(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
object(GMP)#%d (1) {
|
||||
["num"]=>
|
||||
|
@ -28,6 +28,8 @@ int(0)
|
||||
int(-1)
|
||||
int(1)
|
||||
int(1)
|
||||
|
||||
Warning: gmp_neg(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
|
@ -22,6 +22,7 @@ var_dump(gmp_abs(array()));
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
string(1) "0"
|
||||
string(1) "0"
|
||||
@ -31,7 +32,11 @@ string(1) "0"
|
||||
string(21) "111111111111111111111"
|
||||
string(21) "111111111111111111111"
|
||||
string(1) "0"
|
||||
|
||||
Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
|
||||
Warning: gmp_abs(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
|
||||
Warning: gmp_abs() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
|
@ -25,7 +25,11 @@ int(1)
|
||||
int(0)
|
||||
int(1)
|
||||
int(-1)
|
||||
|
||||
Warning: gmp_sign(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
int(0)
|
||||
|
||||
Warning: gmp_sign() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
|
@ -31,6 +31,8 @@ string(5) "40994"
|
||||
string(3) "515"
|
||||
string(4) "3333"
|
||||
string(4) "4544"
|
||||
|
||||
Warning: gmp_and(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
string(4) "1536"
|
||||
string(15) "424703623692768"
|
||||
|
@ -31,6 +31,8 @@ string(6) "517363"
|
||||
string(10) "2342341163"
|
||||
string(2) "-1"
|
||||
string(3) "-19"
|
||||
|
||||
Warning: gmp_or(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
string(15) "987657876576252"
|
||||
string(21) "987658441719689394144"
|
||||
|
@ -26,6 +26,8 @@ echo "Done\n";
|
||||
--EXPECTF--
|
||||
string(2) "-1"
|
||||
string(2) "-1"
|
||||
|
||||
Warning: gmp_com(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
string(14) "-2394876545679"
|
||||
string(3) "110"
|
||||
|
@ -31,6 +31,8 @@ string(6) "476369"
|
||||
string(10) "2342340648"
|
||||
string(5) "-3334"
|
||||
string(5) "-4563"
|
||||
|
||||
Warning: gmp_xor(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
string(15) "987657876574716"
|
||||
string(21) "987658017016065701376"
|
||||
|
@ -37,7 +37,13 @@ NULL
|
||||
|
||||
Warning: gmp_init(): Bad base for conversion: -1 (should be between 2 and %d) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: gmp_init(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
Done
|
||||
|
@ -34,6 +34,8 @@ string(6) "100003"
|
||||
|
||||
Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s on line %d
|
||||
string(1) "0"
|
||||
|
||||
Warning: gmp_nextprime(): Unable to convert variable to GMP - string is not an integer in %s on line %d
|
||||
string(1) "0"
|
||||
|
||||
Warning: gmp_nextprime(): Unable to convert variable to GMP - wrong type in %s on line %d
|
||||
|
Loading…
Reference in New Issue
Block a user