From 54ebcce10b5ca9f517c1f55e1b59b1371dd1d81c Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 19 Nov 2006 20:35:19 -0500 Subject: Allocate a more sane amount of memory. --- lib/args.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/args.c b/lib/args.c index 8b105e00..0a3099cc 100644 --- a/lib/args.c +++ b/lib/args.c @@ -120,7 +120,7 @@ static int gotflag(void) void get_optflags(void) { - int stopearly = 0, optarg = 0, nodash = 0, minargs = 0, maxargs = INT_MAX; + int stopearly = 0, optarg = 0, nodash = 0, minargs = 0, maxargs; struct longopts { struct longopts *next; struct opts *opt; @@ -130,6 +130,13 @@ void get_optflags(void) long *nextarg = (long *)&toy; char *options = toys.which->options; + // Allocate memory for optargs + maxargs = 0; + while (toys.argv[maxargs++]); + toys.optargs = xzalloc(sizeof(char *)*maxargs); + maxargs = INT_MAX; + + // Parse option format if (options) { // Parse leading special behavior indicators for (;;) { @@ -208,7 +215,6 @@ void get_optflags(void) gof.argc = 0; for (gof.this = gof.opts; gof.this; gof.this = gof.this->next) gof.this->shift = gof.argc++; - toys.optargs = xzalloc(sizeof(char *)*(++gof.argc)); // Iterate through command line arguments, skipping argv[0] for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) { -- cgit v1.2.3