PATCH 2/6: print invalid option to getopts correctly

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
---

This one can't use unmeta_one because we just unmetafy()ed optstr.

 Src/builtin.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index f61a41af33..723d5b8e73 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5677,6 +5677,7 @@ bin_getopts(UNUSED(char *name), char **argv, Options ops, UNUSED(int func))
     char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
     char **args = (*argv) ? argv : pparams;
     char *str, optbuf[2] = " ", *p, opch;
+    convchar_t wopch;
 
     // note that resetting + restoring OPTIND happens in doshfunc(), so using -p
     // or enabling POSIX_BUILTINS inside a function that calls getopts is not
@@ -5718,7 +5719,9 @@ bin_getopts(UNUSED(char *name), char **argv, Options ops, UNUSED(int func))
 	}
 	optcind++;
     }
-    opch = str[optcind++];
+    opch = str[optcind];
+    MB_CHARINIT();
+    optcind += MB_CHARLENCONV(str + optcind, lenstr - optcind, &wopch);
     if(str[0] == '+') {
 	optbuf[0] = '+';
 	lenoptbuf = 2;
@@ -5740,7 +5743,7 @@ bin_getopts(UNUSED(char *name), char **argv, Options ops, UNUSED(int func))
 	    zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
 	} else {
 	    zwarn("bad option: %c%c",
-		  "?-+"[lenoptbuf], opch);
+		  "?-+"[lenoptbuf], wopch);
 	    zoptarg=ztrdup("");
 	}
 	return 0;
@@ -5763,7 +5766,7 @@ bin_getopts(UNUSED(char *name), char **argv, Options ops, UNUSED(int func))
 		    setsparam(var, ztrdup("?"));
 		    zoptarg = ztrdup("");
 		    zwarn("argument expected after %c%c option",
-			  "?-+"[lenoptbuf], opch);
+			  "?-+"[lenoptbuf], wopch);
 		}
 		return 0;
 	    }
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.