Here is an alternative patch to solve the problem without attempting to
count parameters. Space for ten parameters is stored statically; this is
expanded in blocks of ten as required.
Take your pick :-)
diff -Naur netkit-ftp-0.17/ftp/main.c netkit-ftp-0.17.patch2/ftp/main.c
--- netkit-ftp-0.17/ftp/main.c 2008-12-15 09:56:19.000000000 +0000
+++ netkit-ftp-0.17.patch2/ftp/main.c 2008-12-15 10:01:22.000000000 +0000
@@ -479,23 +479,15 @@
makeargv(int *pargc, char **parg)
{
static char **rargv = NULL;
+ static int arglimit = 0;
int rargc = 0;
- int i = 0, count = 0;
char **argp;
-
- /* Allocate enough space: err on the side of caution */
- while ( line[i] != '\0' ) {
- if ( line[i] == ' ' )
- count += 1 ;
- i+= 1;
- }
-
- /* allocate memory for $count-sized array of chars */
- rargv = (char **) malloc( count * strlen(line));
- if (rargv == NULL)
- fatal("Out of memory");
-
+ if (arglimit == 0) {
+ arglimit = 10;
+ rargv = malloc(arglimit * sizeof(char*));
+ if (rargv == NULL) fatal ("Out of memory");
+ }
INTOFF;
argbuf = obstack_alloc(&mainobstack, strlen(line) + 1);
INTON;
@@ -503,8 +495,15 @@
stringbase = line; /* scan from first of buffer */
argbase = argbuf; /* store from first of buffer */
slrflag = 0;
- while ((*argp++ = slurpstring())!=NULL)
+ while ((*argp++ = slurpstring())!=NULL) {
rargc++;
+ if (rargc == arglimit) {
+ arglimit += 10;
+ rargv = realloc(rargv, arglimit * sizeof(char*));
+ if (rargv == NULL) fatal ("Out of memory");
+ }
+ }
*pargc = rargc;
if (parg) *parg = altarg;
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]