diff options
author | Rob Landley <rob@landley.net> | 2006-11-19 20:35:19 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-11-19 20:35:19 -0500 |
commit | 54ebcce10b5ca9f517c1f55e1b59b1371dd1d81c (patch) | |
tree | 2adca5c319de87ac45d34247f5f747c1756cb7d8 /lib | |
parent | 4541e881568708cc9462f67abecf01ee55e6e611 (diff) | |
download | toybox-54ebcce10b5ca9f517c1f55e1b59b1371dd1d81c.tar.gz |
Allocate a more sane amount of memory.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/args.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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++) { |