diff options
| author | Mikael Magnusson <mikachu@gmail.com> | 2026-06-07 01:44:29 +0200 |
|---|---|---|
| committer | Mikael Magnusson <mikachu@gmail.com> | 2026-06-14 01:56:15 +0200 |
| commit | 182bef391e514b7e3b905212e18f3ad3c5dcc967 (patch) | |
| tree | d92fbdbe9c44467884d731fc7b6e992ea48d33e9 | |
| parent | 54710: handle multibyte arguments in error messages (diff) | |
| download | zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar.gz zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar.bz2 zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar.lz zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar.xz zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.tar.zst zsh-182bef391e514b7e3b905212e18f3ad3c5dcc967.zip | |
54711: print invalid option to getopts correctly
| -rw-r--r-- | ChangeLog | 2 | ||||
| -rw-r--r-- | Src/builtin.c | 9 |
2 files changed, 8 insertions, 3 deletions
@@ -1,5 +1,7 @@ 2026-06-14 Mikael Magnusson <mikachu@gmail.com> + * 54711: Src/builtin.c: print invalid option to getopts correctly + * 54710: Src/Builtins/rlimits.c, Src/Builtins/sched.c, Src/Modules/stat.c, Src/Modules/system.c, Src/Modules/zftp.c, Src/Zle/complete.c, Src/Zle/zle_thingy.c, Src/builtin.c, diff --git a/Src/builtin.c b/Src/builtin.c index cc63a53f1..ba7740072 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5659,6 +5659,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 @@ -5700,7 +5701,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; @@ -5722,7 +5725,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; @@ -5745,7 +5748,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; } |
