Mercurial > hg > toybox
changeset 28:be59ed005902
Allocate a more sane amount of memory.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 19 Nov 2006 20:35:19 -0500 |
parents | c471910a14e4 |
children | 5566beb17d5a |
files | lib/args.c |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/args.c Sun Nov 19 20:35:05 2006 -0500 +++ b/lib/args.c Sun Nov 19 20:35:19 2006 -0500 @@ -120,7 +120,7 @@ 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 @@ 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 @@ 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++) {