@@ -1524,6 +1524,10 @@ ZEND_FUNCTION(gmp_random_range)
15241524}
15251525/* }}} */
15261526
1527+ static bool gmp_is_bit_index_valid (zend_long index ) {
1528+ return index >= 0 && (index / GMP_NUMB_BITS < INT_MAX );
1529+ }
1530+
15271531/* {{{ Sets or clear bit in a */
15281532ZEND_FUNCTION (gmp_setbit )
15291533{
@@ -1536,12 +1540,8 @@ ZEND_FUNCTION(gmp_setbit)
15361540 RETURN_THROWS ();
15371541 }
15381542
1539- if (index < 0 ) {
1540- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1541- RETURN_THROWS ();
1542- }
1543- if (index / GMP_NUMB_BITS >= INT_MAX ) {
1544- zend_argument_value_error (2 , "must be less than %d * %d" , INT_MAX , GMP_NUMB_BITS );
1543+ if (!gmp_is_bit_index_valid (index )) {
1544+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
15451545 RETURN_THROWS ();
15461546 }
15471547
@@ -1566,8 +1566,8 @@ ZEND_FUNCTION(gmp_clrbit)
15661566 RETURN_THROWS ();
15671567 }
15681568
1569- if (index < 0 ) {
1570- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1569+ if (! gmp_is_bit_index_valid ( index ) ) {
1570+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
15711571 RETURN_THROWS ();
15721572 }
15731573
@@ -1587,8 +1587,8 @@ ZEND_FUNCTION(gmp_testbit)
15871587 Z_PARAM_LONG (index )
15881588 ZEND_PARSE_PARAMETERS_END ();
15891589
1590- if (index < 0 ) {
1591- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1590+ if (! gmp_is_bit_index_valid ( index ) ) {
1591+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
15921592 RETURN_THROWS ();
15931593 }
15941594
@@ -1634,8 +1634,8 @@ ZEND_FUNCTION(gmp_scan0)
16341634 Z_PARAM_LONG (start )
16351635 ZEND_PARSE_PARAMETERS_END ();
16361636
1637- if (start < 0 ) {
1638- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1637+ if (! gmp_is_bit_index_valid ( start ) ) {
1638+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
16391639 RETURN_THROWS ();
16401640 }
16411641
@@ -1654,8 +1654,8 @@ ZEND_FUNCTION(gmp_scan1)
16541654 Z_PARAM_LONG (start )
16551655 ZEND_PARSE_PARAMETERS_END ();
16561656
1657- if (start < 0 ) {
1658- zend_argument_value_error (2 , "must be greater than or equal to 0" );
1657+ if (! gmp_is_bit_index_valid ( start ) ) {
1658+ zend_argument_value_error (2 , "must be between 0 and %d * %d" , INT_MAX , GMP_NUMB_BITS );
16591659 RETURN_THROWS ();
16601660 }
16611661
0 commit comments