PR/43981: Aleksey Cheusov: awk too small limit on number -f options

remove the limit
should we pullup to 5.x?
This commit is contained in:
christos 2010-10-17 22:12:22 +00:00
parent 5c3f6e3eb4
commit 7aa51b5177

View File

@ -51,9 +51,10 @@ int compile_time = 2; /* for error printing: */
#define MAX_PFILE 20 /* max number of -f's */ #define MAX_PFILE 20 /* max number of -f's */
char *pfile[MAX_PFILE]; /* program filenames from -f's */ static char **pfile = NULL; /* program filenames from -f's */
int npfile = 0; /* number of filenames */ static size_t maxpfile = 0; /* max program filenames */
int curpfile = 0; /* current filename */ static size_t npfile = 0; /* number of filenames */
static size_t curpfile = 0; /* current filename */
int safe = 0; /* 1 => "safe" mode */ int safe = 0; /* 1 => "safe" mode */
@ -146,8 +147,14 @@ int main(int argc, char *argv[])
argv++; argv++;
if (argc <= 1) if (argc <= 1)
FATAL("no program filename"); FATAL("no program filename");
if (npfile >= MAX_PFILE - 1) if (npfile >= maxpfile) {
FATAL("too many -f options"); maxpfile += 20;
pfile = realloc(pfile,
maxpfile * sizeof(*pfile));
if (pfile == NULL)
FATAL("error allocating space for "
"-f options");
}
pfile[npfile++] = argv[1]; pfile[npfile++] = argv[1];
break; break;
case 'F': /* set field separator */ case 'F': /* set field separator */