@@ -525,7 +525,7 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_strin
525
525
}
526
526
/* }}} */
527
527
528
- static const char * zend_parse_arg_impl (int arg_num , zval * arg , va_list * va , const char * * spec , char * * error ) /* {{{ */
528
+ static const char * zend_parse_arg_impl (zval * arg , va_list * va , const char * * spec , char * * error ) /* {{{ */
529
529
{
530
530
const char * spec_walk = * spec ;
531
531
char c = * spec_walk ++ ;
@@ -794,12 +794,12 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
794
794
}
795
795
/* }}} */
796
796
797
- static int zend_parse_arg (int arg_num , zval * arg , va_list * va , const char * * spec , int flags ) /* {{{ */
797
+ static int zend_parse_arg (uint32_t arg_num , zval * arg , va_list * va , const char * * spec , int flags ) /* {{{ */
798
798
{
799
799
const char * expected_type = NULL ;
800
800
char * error = NULL ;
801
801
802
- expected_type = zend_parse_arg_impl (arg_num , arg , va , spec , & error );
802
+ expected_type = zend_parse_arg_impl (arg , va , spec , & error );
803
803
if (expected_type ) {
804
804
if (EG (exception )) {
805
805
return FAILURE ;
@@ -822,7 +822,7 @@ static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec
822
822
}
823
823
/* }}} */
824
824
825
- ZEND_API int zend_parse_parameter (int flags , int arg_num , zval * arg , const char * spec , ...)
825
+ ZEND_API int zend_parse_parameter (int flags , uint32_t arg_num , zval * arg , const char * spec , ...)
826
826
{
827
827
va_list va ;
828
828
int ret ;
@@ -843,16 +843,17 @@ static ZEND_COLD void zend_parse_parameters_debug_error(const char *msg) {
843
843
ZSTR_VAL (active_function -> common .function_name ), msg );
844
844
}
845
845
846
- static int zend_parse_va_args (int num_args , const char * type_spec , va_list * va , int flags ) /* {{{ */
846
+ static int zend_parse_va_args (uint32_t num_args , const char * type_spec , va_list * va , int flags ) /* {{{ */
847
847
{
848
848
const char * spec_walk ;
849
- int c , i ;
850
- int min_num_args = -1 ;
851
- int max_num_args = 0 ;
852
- int post_varargs = 0 ;
849
+ char c ;
850
+ uint32_t i ;
851
+ uint32_t min_num_args = 0 ;
852
+ uint32_t max_num_args = 0 ;
853
+ uint32_t post_varargs = 0 ;
853
854
zval * arg ;
854
- int arg_count ;
855
855
zend_bool have_varargs = 0 ;
856
+ zend_bool have_optional_args = 0 ;
856
857
zval * * varargs = NULL ;
857
858
int * n_varargs = NULL ;
858
859
@@ -874,6 +875,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
874
875
875
876
case '|' :
876
877
min_num_args = max_num_args ;
878
+ have_optional_args = 1 ;
877
879
break ;
878
880
879
881
case '/' :
@@ -903,35 +905,34 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
903
905
}
904
906
}
905
907
906
- if (min_num_args < 0 ) {
908
+ /* with no optional arguments the minimum number of arguments must be the same as the maximum */
909
+ if (!have_optional_args ) {
907
910
min_num_args = max_num_args ;
908
911
}
909
912
910
913
if (have_varargs ) {
911
914
/* calculate how many required args are at the end of the specifier list */
912
915
post_varargs = max_num_args - post_varargs ;
913
- max_num_args = -1 ;
914
916
}
915
917
916
- if (num_args < min_num_args || (num_args > max_num_args && max_num_args >= 0 )) {
918
+ if (num_args < min_num_args || (num_args > max_num_args && ! have_varargs )) {
917
919
if (!(flags & ZEND_PARSE_PARAMS_QUIET )) {
918
920
zend_function * active_function = EG (current_execute_data )-> func ;
919
921
const char * class_name = active_function -> common .scope ? ZSTR_VAL (active_function -> common .scope -> name ) : "" ;
920
922
zend_argument_count_error ("%s%s%s() expects %s %d parameter%s, %d given" ,
921
923
class_name ,
922
924
class_name [0 ] ? "::" : "" ,
923
925
ZSTR_VAL (active_function -> common .function_name ),
924
- min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most" ,
926
+ (min_num_args == max_num_args && !have_varargs ) ? "exactly" :
927
+ num_args < min_num_args ? "at least" : "at most" ,
925
928
num_args < min_num_args ? min_num_args : max_num_args ,
926
929
(num_args < min_num_args ? min_num_args : max_num_args ) == 1 ? "" : "s" ,
927
930
num_args );
928
931
}
929
932
return FAILURE ;
930
933
}
931
934
932
- arg_count = ZEND_CALL_NUM_ARGS (EG (current_execute_data ));
933
-
934
- if (num_args > arg_count ) {
935
+ if (num_args > ZEND_CALL_NUM_ARGS (EG (current_execute_data ))) {
935
936
zend_parse_parameters_debug_error ("could not obtain parameters for parsing" );
936
937
return FAILURE ;
937
938
}
@@ -979,7 +980,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
979
980
}
980
981
/* }}} */
981
982
982
- ZEND_API int zend_parse_parameters_ex (int flags , int num_args , const char * type_spec , ...) /* {{{ */
983
+ ZEND_API int zend_parse_parameters_ex (int flags , uint32_t num_args , const char * type_spec , ...) /* {{{ */
983
984
{
984
985
va_list va ;
985
986
int retval ;
@@ -992,7 +993,7 @@ ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_
992
993
}
993
994
/* }}} */
994
995
995
- ZEND_API int zend_parse_parameters (int num_args , const char * type_spec , ...) /* {{{ */
996
+ ZEND_API int zend_parse_parameters (uint32_t num_args , const char * type_spec , ...) /* {{{ */
996
997
{
997
998
va_list va ;
998
999
int retval ;
@@ -1006,7 +1007,7 @@ ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /*
1006
1007
}
1007
1008
/* }}} */
1008
1009
1009
- ZEND_API int zend_parse_method_parameters (int num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1010
+ ZEND_API int zend_parse_method_parameters (uint32_t num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1010
1011
{
1011
1012
va_list va ;
1012
1013
int retval ;
@@ -1046,7 +1047,7 @@ ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const ch
1046
1047
}
1047
1048
/* }}} */
1048
1049
1049
- ZEND_API int zend_parse_method_parameters_ex (int flags , int num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1050
+ ZEND_API int zend_parse_method_parameters_ex (int flags , uint32_t num_args , zval * this_ptr , const char * type_spec , ...) /* {{{ */
1050
1051
{
1051
1052
va_list va ;
1052
1053
int retval ;
0 commit comments