Page MenuHomeFreeBSD

D21971.diff
No OneTemporary

D21971.diff

Index: head/usr.bin/rpcgen/rpc_main.c
===================================================================
--- head/usr.bin/rpcgen/rpc_main.c
+++ head/usr.bin/rpcgen/rpc_main.c
@@ -93,19 +93,13 @@
*/
static void addarg(const char *); /* add another argument to the list */
static void insarg(int, const char *); /* insert arg at specified location */
-static void clear_args(void); /* clear argument list */
static void checkfiles(const char *, const char *);
/* check if out file already exists */
+static char **arglist;
+static int argcount = 0;
+static int argmax = 0;
-
-#define ARGLISTLEN 20
-#define FIXEDARGS 0
-
-static char *arglist[ARGLISTLEN];
-static int argcount = FIXEDARGS;
-
-
int nonfatalerrors; /* errors */
int inetdflag = 0; /* Support for inetd is disabled by default, use -I */
int pmflag = 0; /* Support for port monitors is disabled by default */
@@ -141,7 +135,6 @@
struct commandline cmd;
(void) memset((char *)&cmd, 0, sizeof (struct commandline));
- clear_args();
if (!parseargs(argc, argv, &cmd))
usage();
/*
@@ -273,16 +266,6 @@
f_print(fout, " */\n\n");
}
-/* clear list of arguments */
-static void
-clear_args(void)
-{
- int i;
- for (i = FIXEDARGS; i < ARGLISTLEN; i++)
- arglist[i] = NULL;
- argcount = FIXEDARGS;
-}
-
/* prepend C-preprocessor and flags before arguments */
static void
prepend_cpp(void)
@@ -925,21 +908,40 @@
}
/*
- * Add another argument to the arg list
+ * Extend the argument list
*/
static void
-addarg(const char *cp)
+moreargs(void)
{
- if (argcount >= ARGLISTLEN) {
- warnx("too many defines");
+ char **newarglist;
+
+ argmax = argmax == 0 ? 32 : argmax << 1;
+ if (argmax > INT_MAX / 4) {
+ warnx("refusing to allocate too many arguments");
crash();
- /*NOTREACHED*/
}
+ newarglist = realloc(arglist, argmax * sizeof(*arglist));
+ if (newarglist == NULL) {
+ warnx("unable to allocate arglist");
+ crash();
+ }
+ free(arglist);
+ arglist = newarglist;
+}
+
+/*
+ * Add another argument to the arg list
+ */
+static void
+addarg(const char *cp)
+{
+ if (argcount >= argmax)
+ moreargs();
+
if (cp != NULL)
arglist[argcount++] = xstrdup(cp);
else
arglist[argcount++] = NULL;
-
}
/*
@@ -950,11 +952,8 @@
{
int i;
- if (argcount >= ARGLISTLEN) {
- warnx("too many defines");
- crash();
- /*NOTREACHED*/
- }
+ if (argcount >= argmax)
+ moreargs();
/* Move up existing arguments */
for (i = argcount - 1; i >= place; i--)

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 19, 1:55 PM (13 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25639341
Default Alt Text
D21971.diff (2 KB)

Event Timeline