diff options
author | jilles <jilles@FreeBSD.org> | 2015-11-01 22:07:40 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-11-01 22:07:40 +0000 |
commit | f6a99fcfe010450af7712810547f5917d50de1ea (patch) | |
tree | d5b1f5b5fcbf40c4da6a558667b755e8dc19e4b1 /bin/sh/eval.c | |
parent | 3c974d824dd35fae22536bf504300458be0872f2 (diff) | |
download | FreeBSD-src-f6a99fcfe010450af7712810547f5917d50de1ea.zip FreeBSD-src-f6a99fcfe010450af7712810547f5917d50de1ea.tar.gz |
sh: Avoid copying argv for simple commands.
Add dummy entries before and after so arglist's array is directly usable as
argv.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index dfbbc04..46c00de 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -750,7 +750,7 @@ isdeclarationcmd(struct narg *arg) } static void -xtracecommand(struct arglist *varlist, struct arglist *arglist) +xtracecommand(struct arglist *varlist, int argc, char **argv) { char sep = 0; const char *text, *p, *ps4; @@ -771,8 +771,8 @@ xtracecommand(struct arglist *varlist, struct arglist *arglist) out2qstr(text); sep = ' '; } - for (i = 0; i < arglist->count; i++) { - text = arglist->args[i]; + for (i = 0; i < argc; i++) { + text = argv[i]; if (sep != 0) out2c(' '); out2qstr(text); @@ -849,6 +849,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) do_clearcmdentry = 0; oexitstatus = exitstatus; exitstatus = 0; + /* Add one slot at the beginning for tryexec(). */ + appendarglist(&arglist, nullstr); for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { if (varflag && isassignment(argp->narg.text)) { expandarg(argp, varflag == 1 ? &varlist : &arglist, @@ -858,13 +860,11 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) varflag = isdeclarationcmd(&argp->narg) ? 2 : 0; expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); } + appendarglist(&arglist, nullstr); expredir(cmd->ncmd.redirect); - argc = arglist.count; - /* Add one slot at the beginning for tryexec(). */ - argv = stalloc(sizeof (char *) * (argc + 2)); - argv++; + argc = arglist.count - 2; + argv = &arglist.args[1]; - memcpy(argv, arglist.args, sizeof(*argv) * argc); argv[argc] = NULL; lastarg = NULL; if (iflag && funcnest == 0 && argc > 0) @@ -872,7 +872,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) /* Print the command if xflag is set. */ if (xflag) - xtracecommand(&varlist, &arglist); + xtracecommand(&varlist, argc, argv); /* Now locate the command. */ if (argc == 0) { |