Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] "emulate" accidentally allows "--version" and "--help"



Because it shares option parsing code with shell startup, it is possible
to run "emulate zsh --version" or "emulate ksh --help" and so on.  The
result is unexpected and usually inaccurate given the context, and also
confuses other option parsing, so it's probably best to disallow it.


diff --git a/Src/init.c b/Src/init.c
index a1162b3..d8c26ac 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -376,12 +376,12 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
 	    *argv = "--";
 	while (*++*argv) {
 	    if (**argv == '-') {
-		if(!argv[0][1]) {
+		if (!argv[0][1]) {
 		    /* The pseudo-option `--' signifies the end of options. */
 		    argv++;
 		    goto doneoptions;
 		}
-		if(*argv != args+1 || **argv != '-')
+		if (nam || *argv != args+1 || **argv != '-')
 		    goto badoptionstring;
 		/* GNU-style long options */
 		++*argv;



Messages sorted by: Reverse Date, Date, Thread, Author