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

PATCH 4/6: fix multibyte error reporting in zparseopts



This one is complicated by the fact it's using fprintf. If the user
passed a nonprintable char as an option, we shouldn't print that, which
nicechar handles for us.

Fixes 54077.

---

It would be great if there was some kind of generic MB_NICECHAR or so,
but there isn't (stay tuned for PATCH 5/6 coming up in your mailbox).

 Src/Modules/zutil.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index add0554600..0bc340dc90 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -1988,10 +1988,19 @@ bin_zparseopts(char *nam, char **args, Options ops, UNUSED(int func))
 	    while (*++o) {
 		if (!(d = sopts[(unsigned char) *o])) {
 		    if (fail) {
-			if (*o != '-' || o > *pp + 1)
-			    fprintf(stderr, "%s: bad option: -%c\n", progname, *o);
-			else
+			if (*o != '-' || o > *pp + 1) {
+			    convchar_t wc = unmeta_one(o, NULL);
+			    fprintf(stderr, "%s: bad option: -", progname);
+#ifdef MULTIBYTE_SUPPORT
+			    mb_charinit();
+			    zputs(wcs_nicechar(wc, NULL, NULL), stderr);
+#else
+			    zputs(nicechar(wc), stderr);
+#endif
+			    fputc('\n', stderr);
+			} else {
 			    fprintf(stderr, "%s: bad option: -%s\n", progname, o);
+			}
 			return 1;
 		    }
 		    o = NULL;
-- 
2.38.1





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