1515#include <limits.h>
1616#include <dirent.h>
1717
18- #define MAX_PARAM 8
19-
2018/*
2119 * returns the last-modified time of the file
2220 *
@@ -900,15 +898,16 @@ void par_freepartable(par_t **ptable_pp, int pcount) {
900898 * YOU MUST FREE THAT TABLE BY USING par_freepartable()
901899 * IF THERE IS NO ERROR, CALL TO par_freepartable IS NOT NEEDED
902900 */
903- int par_getpartable (par_t * * ptable_pp , const char * valid_sep ) {
901+ int par_getpartable (par_t * * ptable_pp , const char * valid_sep , unsigned max_items ) {
904902 bcip_t ofs ;
905903 char vsep [8 ];
906904
907905 // initialize
908906 var_t * par = NULL ;
909907 byte last_sep = 0 ;
910908 int pcount = 0 ;
911- par_t * ptable = * ptable_pp = malloc (sizeof (par_t ) * MAX_PARAM );
909+
910+ par_t * ptable = * ptable_pp = malloc (sizeof (par_t ) * max_items );
912911
913912 if (valid_sep ) {
914913 strlcpy (vsep , valid_sep , sizeof (vsep ));
@@ -954,9 +953,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
954953 if (code_isvar ()) {
955954 // push parameter
956955 ptable [pcount ].var = code_getvarptr ();
957- if (++ pcount == MAX_PARAM ) {
956+ if (++ pcount == max_items ) {
958957 par_freepartable (ptable_pp , pcount );
959- err_parfmt (__FILE__ );
958+ err_parfmt (ERR_PARAM_TOO_MANY );
960959 return -1 ;
961960 }
962961 break ;
@@ -974,9 +973,9 @@ int par_getpartable(par_t **ptable_pp, const char *valid_sep) {
974973 // push parameter
975974 ptable [pcount ].var = par ;
976975 ptable [pcount ].flags = PAR_BYVAL ;
977- if (++ pcount == MAX_PARAM ) {
976+ if (++ pcount == max_items ) {
978977 par_freepartable (ptable_pp , pcount );
979- err_parfmt (__FILE__ );
978+ err_parfmt (ERR_PARAM_TOO_MANY );
980979 return -1 ;
981980 }
982981 } else {
@@ -1047,7 +1046,7 @@ int par_massget_type_check(char fmt, par_t *par) {
10471046int par_massget (const char * fmt , ...) {
10481047 // get ptable
10491048 par_t * ptable ;
1050- int pcount = par_getpartable (& ptable , NULL );
1049+ int pcount = par_getpartable (& ptable , NULL , MAX_PARAMS );
10511050 if (pcount == -1 ) {
10521051 free (ptable );
10531052 return -1 ;
0 commit comments