@@ -527,7 +527,7 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_strin
527
527
}
528
528
/* }}} */
529
529
530
- static const char * zend_parse_arg_impl (int arg_num , zval * arg , va_list * va , const char * * spec , char * * error ) /* {{{ */
530
+ static const char * zend_parse_arg_impl (zval * arg , va_list * va , const char * * spec , char * * error ) /* {{{ */
531
531
{
532
532
const char * spec_walk = * spec ;
533
533
char c = * spec_walk ++ ;
@@ -796,12 +796,12 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
796
796
}
797
797
/* }}} */
798
798
799
- static int zend_parse_arg (int arg_num , zval * arg , va_list * va , const char * * spec , int flags ) /* {{{ */
799
+ static int zend_parse_arg (uint32_t arg_num , zval * arg , va_list * va , const char * * spec , int flags ) /* {{{ */
800
800
{
801
801
const char * expected_type = NULL ;
802
802
char * error = NULL ;
803
803
804
- expected_type = zend_parse_arg_impl (arg_num , arg , va , spec , & error );
804
+ expected_type = zend_parse_arg_impl (arg , va , spec , & error );
805
805
if (expected_type ) {
806
806
if (EG (exception )) {
807
807
return FAILURE ;
@@ -824,7 +824,7 @@ static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec
824
824
}
825
825
/* }}} */
826
826
827
- ZEND_API int zend_parse_parameter (int flags , int arg_num , zval * arg , const char * spec , ...)
827
+ ZEND_API int zend_parse_parameter (int flags , uint32_t arg_num , zval * arg , const char * spec , ...)
828
828
{
829
829
va_list va ;
830
830
int ret ;
@@ -845,16 +845,17 @@ static ZEND_COLD void zend_parse_parameters_debug_error(const char *msg) {
845
845
ZSTR_VAL (active_function -> common .function_name ), msg );
846
846
}
847
847
848
- static int zend_parse_va_args (int num_args , const char * type_spec , va_list * va , int flags ) /* {{{ */
848
+ static int zend_parse_va_args (uint32_t num_args , const char * type_spec , va_list * va , int flags ) /* {{{ */
849
849
{
850
850
const char * spec_walk ;
851
- int c , i ;
852
- int min_num_args = -1 ;
853
- int max_num_args = 0 ;
854
- int post_varargs = 0 ;
851
+ char c ;
852
+ uint32_t i ;
853
+ uint32_t min_num_args = 0 ;
854
+ uint32_t max_num_args = 0 ;
855
+ uint32_t post_varargs = 0 ;
855
856
zval * arg ;
856
- int arg_count ;
857
857
zend_bool have_varargs = 0 ;
858
+ zend_bool have_optional_args = 0 ;
858
859
zval * * varargs = NULL ;
859
860
int * n_varargs = NULL ;
860
861
@@ -876,6 +877,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
876
877
877
878
case '|' :
878
879
min_num_args = max_num_args ;
880
+ have_optional_args = 1 ;
879
881
break ;
880
882
881
883
case '/' :
@@ -905,17 +907,18 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
905
907
}
906
908
}
907
909
908
- if (min_num_args < 0 ) {
910
+ /* with no optional arguments the minimum number of arguments must be the same as the maximum */
911
+ if (!have_optional_args ) {
909
912
min_num_args = max_num_args ;
910
913
}
911
914
912
915
if (have_varargs ) {
913
916
/* calculate how many required args are at the end of the specifier list */
914
917
post_varargs = max_num_args - post_varargs ;
915
- max_num_args = -1 ;
918
+ max_num_args = UINT32_MAX ;
916
919
}
917
920
918
- if (num_args < min_num_args || ( num_args > max_num_args && max_num_args >= 0 ) ) {
921
+ if (num_args < min_num_args || num_args > max_num_args ) {
919
922
if (!(flags & ZEND_PARSE_PARAMS_QUIET )) {
920
923
zend_function * active_function = EG (current_execute_data )-> func ;
921
924
const char * class_name = active_function -> common .scope ? ZSTR_VAL (active_function -> common .scope -> name ) : "" ;
@@ -931,9 +934,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
931
934
return FAILURE ;
932
935
}
933
936
934
- arg_count = ZEND_CALL_NUM_ARGS (EG (current_execute_data ));
935
-
936
- if (num_args > arg_count ) {
937
+ if (num_args > ZEND_CALL_NUM_ARGS (EG (current_execute_data ))) {
937
938
zend_parse_parameters_debug_error ("could not obtain parameters for parsing" );
938
939
return FAILURE ;
939
940
}
@@ -981,7 +982,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
981
982
}
982
983
/* }}} */
983
984
984
- ZEND_API int zend_parse_parameters_ex (int flags , int num_args , const char * type_spec , ...) /* {{{ */
985
+ ZEND_API int zend_parse_parameters_ex (int flags , uint32_t num_args , const char * type_spec , ...) /* {{{ */
985
986
{
986
987
va_list va ;
987
988
int retval ;
@@ -994,7 +995,7 @@ ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_
994
995
}
995
996
/* }}} */
996
997
997
- ZEND_API int zend_parse_parameters (int num_args , const char * type_spec , ...) /* {{{ */
998
+ ZEND_API int zend_parse_parameters (uint32_t num_args , const char * type_spec , ...) /* {{{ */
998
999
{
999
1000
va_list va ;
1000
1001
int retval ;
@@ -1008,7 +1009,7 @@ ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /*
1008
1009
}
1009
1010
/* }}} */
1010
1011
1011
- ZEND_API int zend_parse_method_parameters (int num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1012
+ ZEND_API int zend_parse_method_parameters (uint32_t num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1012
1013
{
1013
1014
va_list va ;
1014
1015
int retval ;
@@ -1048,7 +1049,7 @@ ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const ch
1048
1049
}
1049
1050
/* }}} */
1050
1051
1051
- ZEND_API int zend_parse_method_parameters_ex (int flags , int num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1052
+ ZEND_API int zend_parse_method_parameters_ex (int flags , uint32_t num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1052
1053
{
1053
1054
va_list va ;
1054
1055
int retval ;
0 commit comments