@@ -1539,6 +1539,10 @@ ZEND_FUNCTION(gmp_random_range)
15391539}
15401540/* }}} */
15411541
1542+ static bool gmp_is_bit_index_valid (zend_long index ) {
1543+ return index >= 0 && (index / GMP_NUMB_BITS < INT_MAX );
1544+ }
1545+
15421546/* {{{ Sets or clear bit in a */
15431547ZEND_FUNCTION (gmp_setbit )
15441548{
@@ -1551,12 +1555,8 @@ ZEND_FUNCTION(gmp_setbit)
15511555 RETURN_THROWS ();
15521556 }
15531557
1554- if (index < 0 ) {
1555- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1556- RETURN_THROWS ();
1557- }
1558- if (index / GMP_NUMB_BITS >= INT_MAX ) {
1559- zend_argument_value_error (2 , "must be less than %d * %d" , INT_MAX , GMP_NUMB_BITS );
1558+ if (!gmp_is_bit_index_valid (index )) {
1559+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
15601560 RETURN_THROWS ();
15611561 }
15621562
@@ -1581,8 +1581,8 @@ ZEND_FUNCTION(gmp_clrbit)
15811581 RETURN_THROWS ();
15821582 }
15831583
1584- if (index < 0 ) {
1585- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1584+ if (! gmp_is_bit_index_valid ( index ) ) {
1585+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
15861586 RETURN_THROWS ();
15871587 }
15881588
@@ -1602,8 +1602,8 @@ ZEND_FUNCTION(gmp_testbit)
16021602 Z_PARAM_LONG (index )
16031603 ZEND_PARSE_PARAMETERS_END ();
16041604
1605- if (index < 0 ) {
1606- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1605+ if (! gmp_is_bit_index_valid ( index ) ) {
1606+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
16071607 RETURN_THROWS ();
16081608 }
16091609
@@ -1649,8 +1649,8 @@ ZEND_FUNCTION(gmp_scan0)
16491649 Z_PARAM_LONG (start )
16501650 ZEND_PARSE_PARAMETERS_END ();
16511651
1652- if (start < 0 ) {
1653- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1652+ if (! gmp_is_bit_index_valid ( start ) ) {
1653+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
16541654 RETURN_THROWS ();
16551655 }
16561656
@@ -1669,8 +1669,8 @@ ZEND_FUNCTION(gmp_scan1)
16691669 Z_PARAM_LONG (start )
16701670 ZEND_PARSE_PARAMETERS_END ();
16711671
1672- if (start < 0 ) {
1673- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1672+ if (! gmp_is_bit_index_valid ( start ) ) {
1673+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
16741674 RETURN_THROWS ();
16751675 }
16761676
0 commit comments