]> granicus.if.org Git - php/commitdiff
Throw warning when converting invalid string to GMP
authorNikita Popov <nikic@php.net>
Mon, 30 Dec 2013 13:37:32 +0000 (14:37 +0100)
committerNikita Popov <nikic@php.net>
Mon, 30 Dec 2013 13:38:09 +0000 (14:38 +0100)
14 files changed:
ext/gmp/gmp.c
ext/gmp/tests/003.phpt
ext/gmp/tests/005.phpt
ext/gmp/tests/006.phpt
ext/gmp/tests/010.phpt
ext/gmp/tests/012.phpt
ext/gmp/tests/013.phpt
ext/gmp/tests/027.phpt
ext/gmp/tests/029.phpt
ext/gmp/tests/030.phpt
ext/gmp/tests/031.phpt
ext/gmp/tests/032.phpt
ext/gmp/tests/040.phpt
ext/gmp/tests/gmp_nextprime.phpt

index 8835f0524680987c92fc66a276d0df71e883638d..c02b462bab294320072dcb908a5e0b7fbc5f4f31 100644 (file)
@@ -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;
        }
 }
index 379833024d05aa28e87fe62c7e80cc5f06e87a9b..5179b73a1b6e75c0a27692de7e56061a22e81ff0 100644 (file)
@@ -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
index 4ae0cb750a4155092ca0763d7bcd647393659063..79fd73ecf80eb426c084bee7b2c3b69c76b0971c 100644 (file)
@@ -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
index 740760631d4e652b8b87ea148340de32aa79beaf..e1d9df67db7da76d59e15525f52a45a3d125f5fb 100644 (file)
@@ -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
index e3f85ec44f1ecd6da4f3cb9cf15bb79dce3cd203..12e7cad2b32395070b0641814e0d2e00dc69b9f9 100644 (file)
@@ -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"]=>
index 8582ba1fd3732612795a7d03ac7c330b18d23d1b..8ca3471cb8c35db599aef945decaafdbbc7e18dd 100644 (file)
@@ -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)
index 06c2d818d557d4d89ddb36f895d1ae625a11e0c6..bb35891f2a35f83e1698a48b0993c4bf60c05870 100644 (file)
@@ -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
index 71204db98b3bf6b750ddf58a8686d163314a3b57..1efdc28c6f4bd23b7966764cb591f1ab1fdcb54b 100644 (file)
@@ -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
index 1b86e47fd97f9a2f71567057f02ec4570f2d4540..9bc401031b2f541c894c0d2ba842d24d320238cb 100644 (file)
@@ -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"
index 633af41e6fa18f0a6c082e30ed6fca41d1063ebb..035f070bd751bc6b684042aad41353a37b8d0ba4 100644 (file)
@@ -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"
index 90ce1759da6a8875984088537f84b60980ed74e1..1e0c1b4694ac888a314e393025f8eced8abc8d56 100644 (file)
@@ -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"
index 327c979da6cd2f4120b26ce6d5dad57e99bfcc2b..2b0d29a6206e52b18b4c264e55587548c985ead0 100644 (file)
@@ -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"
index 9cc497edc6c1dbd2c3c501ce9bdb02ac67397aea..29640ba7049e1438e99a3d275da67f98123f92e6 100644 (file)
@@ -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
index 5683c8c31fd2eec96c77a5976a4269ce09b3fe03..da89221c0af86783ed05c85e9ff0582adf858957 100644 (file)
@@ -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