From af1c009c3ea97cb4ec79b54c8b208198230e3ffb Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 22 Jun 2020 12:06:43 +0100 Subject: 46079: Ignore double quotes in math expressions. Treat as white space. This is required for compatibility and previously had no use in zsh as it generated an error. --- Src/math.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Src/math.c') diff --git a/Src/math.c b/Src/math.c index 905b910ec..b57ba42d4 100644 --- a/Src/math.c +++ b/Src/math.c @@ -831,6 +831,8 @@ zzlex(void) case ' ': /* Fall through! */ case '\t': case '\n': + case '"': /* POSIX says ignore these */ + case Dnull: break; default: if (idigit(*--ptr) || *ptr == '.') -- cgit v1.2.3 From 0f62e07c802e3fa58d1199f34fcf9772da70c264 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Tue, 6 Apr 2021 23:05:03 +0900 Subject: 48389: getkeystring() should not return ptr to local var Now it returns NULL if called with GETKEY_SINGLE_CHAR and next character is not found. Caller must check the return value. --- ChangeLog | 5 +++++ Src/math.c | 7 ++++++- Src/utils.c | 33 +++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 9 deletions(-) (limited to 'Src/math.c') diff --git a/ChangeLog b/ChangeLog index d2b58a0f1..54d65ae61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-04-06 Jun-ichi Takimoto + + * 48389: Src/math.c, Src/utils.c: getkeystring(GETKEY_SINGLE_CHAR) + should not return a pointer to a local variable + 2021-04-06 Oliver Kiddle * Marc Chantreux: users/26579: Completion/Unix/Command/_surfraw: diff --git a/Src/math.c b/Src/math.c index b57ba42d4..1d0d86639 100644 --- a/Src/math.c +++ b/Src/math.c @@ -840,13 +840,18 @@ zzlex(void) if (*ptr == '#') { if (*++ptr == '\\' || *ptr == '#') { int v; + char *optr = ptr; ptr++; if (!*ptr) { zerr("bad math expression: character missing after ##"); return EOI; } - ptr = getkeystring(ptr, NULL, GETKEYS_MATH, &v); + if(!(ptr = getkeystring(ptr, NULL, GETKEYS_MATH, &v))) { + zerr("bad math expression: bad character after ##"); + ptr = optr; + return EOI; + } yyval.u.l = v; return NUM; } diff --git a/Src/utils.c b/Src/utils.c index 1ac064a4e..5a9222919 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -6697,13 +6697,21 @@ ucs4toutf8(char *dest, unsigned int wval) * * The return value is unmetafied unless GETKEY_DOLLAR_QUOTE is * in use. + * + * If GETKEY_SINGLE_CHAR is set in how, a next character in the given + * string is parsed, and the character code for it is returned in misc. + * The return value of the function is a pointer to the byte in the + * given string from where the next parsing should start. If the next + * character can't be found then NULL is returned. + * CAUTION: Currently, GETKEY_SINGLE_CHAR can be used only via + * GETKEYS_MATH. Other use of it may cause trouble. */ /**/ mod_export char * getkeystring(char *s, int *len, int how, int *misc) { - char *buf, tmp[1]; + char *buf = NULL, tmp[1]; char *t, *tdest = NULL, *u = NULL, *sstart = s, *tbuf = NULL; char svchar = '\0'; int meta = 0, control = 0, ignoring = 0; @@ -6729,9 +6737,11 @@ getkeystring(char *s, int *len, int how, int *misc) DPUTS((how & (GETKEY_DOLLAR_QUOTE|GETKEY_SINGLE_CHAR)) == (GETKEY_DOLLAR_QUOTE|GETKEY_SINGLE_CHAR), "BUG: incompatible options in getkeystring"); + DPUTS((how & GETKEY_SINGLE_CHAR) && (how != GETKEYS_MATH), + "BUG: unsupported options in getkeystring"); if (how & GETKEY_SINGLE_CHAR) - t = buf = tmp; + t = tmp; else { /* Length including terminating NULL */ int maxlen = 1; @@ -7165,13 +7175,20 @@ getkeystring(char *s, int *len, int how, int *misc) */ DPUTS((how & (GETKEY_DOLLAR_QUOTE|GETKEY_UPDATE_OFFSET)) == GETKEY_DOLLAR_QUOTE, "BUG: unterminated $' substitution"); - *t = '\0'; - if (how & GETKEY_DOLLAR_QUOTE) - *tdest = '\0'; - if (how & GETKEY_SINGLE_CHAR) + + if (how & GETKEY_SINGLE_CHAR) { + /* couldn't find a character */ *misc = 0; - else - *len = ((how & GETKEY_DOLLAR_QUOTE) ? tdest : t) - buf; + return NULL; + } + if (how & GETKEY_DOLLAR_QUOTE) { + *tdest = '\0'; + *len = tdest - buf; + } + else { + *t = '\0'; + *len = t - buf; + } return buf; } -- cgit v1.2.3 From 4fa4dcad17f593a8def8799ad1d5258c328d9ead Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Sat, 15 May 2021 14:11:49 -0700 Subject: 48723: locale-safe recognition of "Inf" and "NaN" constants in math --- ChangeLog | 3 +++ Src/math.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Src/math.c') diff --git a/ChangeLog b/ChangeLog index 8e241fa6a..91d45894b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-05-15 Bart Schaefer + * Vincent Lefevre: 48723: Src/math.c: locale-safe recognition of + "Inf" and "NaN" constants + * Peter Stephenson: users/26742: Src/builtin.c: break out of surrounding shell loops when "exit" is called from an exit hook diff --git a/Src/math.c b/Src/math.c index 1d0d86639..ade02d80c 100644 --- a/Src/math.c +++ b/Src/math.c @@ -864,13 +864,17 @@ zzlex(void) p = ptr; ptr = ie; if (ie - p == 3) { - if (strncasecmp(p, "NaN", 3) == 0) { + if ((p[0] == 'N' || p[0] == 'n') && + (p[1] == 'A' || p[1] == 'a') && + (p[2] == 'N' || p[2] == 'n')) { yyval.type = MN_FLOAT; yyval.u.d = 0.0; yyval.u.d /= yyval.u.d; return NUM; } - else if (strncasecmp(p, "Inf", 3) == 0) { + else if ((p[0] == 'I' || p[0] == 'i') && + (p[1] == 'N' || p[1] == 'n') && + (p[2] == 'F' || p[2] == 'f')) { yyval.type = MN_FLOAT; yyval.u.d = 0.0; yyval.u.d = 1.0 / yyval.u.d; -- cgit v1.2.3 From 356dcb20cef387a5eea5f8fcbfe123b24e3bb928 Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Fri, 12 Nov 2021 23:33:37 +0200 Subject: github #82: Fix typos --- ChangeLog | 11 +++++++++++ Completion/BSD/Command/_kdump | 2 +- Completion/BSD/Command/_ktrace | 2 +- Completion/Debian/Command/_aptitude | 2 +- Completion/Linux/Command/_modutils | 2 +- Completion/Linux/Command/_sysstat | 2 +- Completion/Mandriva/Command/_urpmi | 2 +- Completion/Redhat/Command/_dnf | 2 +- Completion/Unix/Command/_ansible | 2 +- Completion/Unix/Command/_gcc | 4 ++-- Etc/FAQ.yo | 4 ++-- Etc/NEWS-4.3 | 2 +- Functions/Chpwd/cdr | 2 +- Functions/Misc/regexp-replace | 2 +- Functions/Newuser/zsh-newuser-install | 2 +- NEWS | 2 +- Src/Zle/compmatch.c | 8 ++++---- Src/exec.c | 2 +- Src/math.c | 4 ++-- Test/A01grammar.ztst | 2 +- Test/B12limit.ztst | 2 +- 21 files changed, 37 insertions(+), 26 deletions(-) (limited to 'Src/math.c') diff --git a/ChangeLog b/ChangeLog index de6bbb08b..1dfe2e39a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2021-11-12 Oliver Kiddle + * github #82: Dimitris Apostolou: Completion/BSD/Command/_kdump, + Completion/Redhat/Command/_dnf, Completion/BSD/Command/_ktrace, + Completion/Linux/Command/_modutils, Test/A01grammar.ztst, + Completion/Linux/Command/_sysstat, Functions/Chpwd/cdr, + Completion/Unix/Command/_ansible, Completion/Unix/Command/_gcc, + Completion/Mandriva/Command/_urpmi, Etc/NEWS-4.3, + Completion/Debian/Command/_aptitude, Etc/FAQ.yo, + Functions/Newuser/zsh-newuser-install, NEWS, + Functions/Misc/regexp-replace, Src/Zle/compmatch.c, + Src/exec.c, Src/math.c, Test/B12limit.ztst: fix typos + * Marlon: 49572: Completion/Base/Completer/_expand, Test/Y01completion.ztst: Let _expand preserve array form w/out zstyle glob diff --git a/Completion/BSD/Command/_kdump b/Completion/BSD/Command/_kdump index 946296a75..e5c7c4cce 100644 --- a/Completion/BSD/Command/_kdump +++ b/Completion/BSD/Command/_kdump @@ -30,7 +30,7 @@ local args=( '-f+[use the specified file (- for stdin)]:dump file:_files' '-l[loop reading the trace file]' '-m+[maximum I/O bytes to display]:max data bytes:' - '-n[supress ad hoc translations]' + '-n[suppress ad hoc translations]' '-p+[show output only for the specified pid]: :_kdump_pid' '(-E -T)-R[display relative timestamps]' '(-E -R )-T[display absolute timestamps]' diff --git a/Completion/BSD/Command/_ktrace b/Completion/BSD/Command/_ktrace index 13c11f15d..9613ba2bf 100644 --- a/Completion/BSD/Command/_ktrace +++ b/Completion/BSD/Command/_ktrace @@ -4,7 +4,7 @@ local args=( '-a[append to the trace file]' '(*)-C[disable tracing on all user owned processes or all processes if executed by root]' '-c[clear the trace points]' - '-d[trace current decendants]' + '-d[trace current descendants]' '-f+[log trace to specified file]:trace file:_files' '(-p *)-g+[enable/disable tracing on specified process group]:pgid:_pgids' '-i[inherit trace flags on future children]' diff --git a/Completion/Debian/Command/_aptitude b/Completion/Debian/Command/_aptitude index 91d233f11..5b10adb80 100644 --- a/Completion/Debian/Command/_aptitude +++ b/Completion/Debian/Command/_aptitude @@ -15,7 +15,7 @@ _arguments -C \ '(-F --display-format)'{-F,--display-format}'[specify output format for search command]:format:->format-strings' \ '--group-by=[control how the versions command groups its output]:grouping:(archive auto none package source-package source-version)' \ '--log-file=[specify output log file]:file:_files' \ - '*--log-level=[specify mimimum message level to log]:level:compadd -o nosort off fatal error warn info debug trace' \ + '*--log-level=[specify minimum message level to log]:level:compadd -o nosort off fatal error warn info debug trace' \ '--log-resolver[set some standard log levels related to the resolver]' \ '(--allow-new-installs)--no-new-installs[prevent safe-upgrade from installing any new packages]' \ '(--allow-new-upgrades)--no-new-upgrades[prevent safe-upgrade from upgrading packages regardless]' \ diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils index 1205f2506..3e46130a2 100644 --- a/Completion/Linux/Command/_modutils +++ b/Completion/Linux/Command/_modutils @@ -105,7 +105,7 @@ _modutils() { loaded-modules|loadable-modules) if [[ -r /proc/modules ]]; then loaded_modules=(${${(f)"$(tp != CPAT_ANY || wp->tp != CPAT_ANY) @@ -1496,7 +1496,7 @@ pattern_match_restrict(Cpattern p, Cpattern wp, convchar_t *wsc, int wsclen, * characters. We're matching two patterns against * one another to generate a character to insert. * This is a bit too psychedelic, so I'm going to - * bale out now. See you on the ground. + * bail out now. See you on the ground. */ return 0; } @@ -1564,7 +1564,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws) c = unmeta_one(s, &len); /* * If either is "?", they match each other; no further tests. - * Apply this even if the character wasn't convertable; + * Apply this even if the character wasn't convertible; * there's no point trying to be clever in that case. */ if (p->tp != CPAT_ANY || wp->tp != CPAT_ANY) @@ -1934,7 +1934,7 @@ bld_line(Cmatcher mp, ZLE_STRING_T line, char *mword, char *word, * This is the nightmare case: we have line and * and word matchers and some pattern which restricts * the value on the line without us knowing exactly - * what it is. Despatch to the special function + * what it is. Dispatch to the special function * for that. */ if (mp && !mp->flags && mp->wlen <= wlen && diff --git a/Src/exec.c b/Src/exec.c index 1f23a862d..1860a10ed 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3954,7 +3954,7 @@ execcmd_exec(Estate state, Execcmd_params eparams, if (type == WC_AUTOFN) { /* * We pre-loaded this to get any redirs. - * So we execuate a simplified function here. + * So we execute a simplified function here. */ lastval = execautofn_basic(state, do_exec); } else diff --git a/Src/math.c b/Src/math.c index ade02d80c..4f24361a4 100644 --- a/Src/math.c +++ b/Src/math.c @@ -162,7 +162,7 @@ static int unary = 1; #define TOKCOUNT 53 /* - * Opeator recedences: in reverse order, i.e. lower number, high precedence. + * Operator precedences: in reverse order, i.e. lower number, high precedence. * These are the C precedences. * * 0 Non-operators: NUM (numeric constant), ID (identifier), @@ -219,7 +219,7 @@ static int c_prec[TOKCOUNT] = }; /* - * Opeator recedences: in reverse order, i.e. lower number, high precedence. + * Operator precedences: in reverse order, i.e. lower number, high precedence. * These are the default zsh precedences. * * 0 Non-operators: NUM (numeric constant), ID (identifier), diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index c114ff103..ac39a4eea 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -922,7 +922,7 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci x=1 x=2 | echo $x echo $x -0:Assignment-only current shell commands in LHS of pipelin +0:Assignment-only current shell commands in LHS of pipeline >1 >1 diff --git a/Test/B12limit.ztst b/Test/B12limit.ztst index 48d33e6e3..9dce59824 100644 --- a/Test/B12limit.ztst +++ b/Test/B12limit.ztst @@ -11,7 +11,7 @@ %test limit | grep UNKNOWN || print OK -0:Check if there is unknown resouce(s) in the system +0:Check if there is unknown resource(s) in the system >OK F:A failure here does not indicate any error in zsh. It just means there F:is a resource in your system that is unknown to zsh developers. Please -- cgit v1.2.3 From b3519a9603e8f7f1c9830e14f918e87daf8fea13 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Tue, 30 Nov 2021 18:27:53 +0100 Subject: 49611 based on 49590 (Martijn Dekker): disable Inf and NaN in math expressions for sh emulation --- ChangeLog | 5 +++++ Src/math.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/math.c') diff --git a/ChangeLog b/ChangeLog index f9ae6a3bb..20bb88d88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-11-30 Oliver Kiddle + + * 49611 based on 49590 (Martijn Dekker): Src/math.c: disable Inf + and NaN in math expressions for sh emulation + 2021-11-28 Oliver Kiddle * 49606: Src/hashnameddir.c, Src/utils.c, configure.ac: remove old diff --git a/Src/math.c b/Src/math.c index 4f24361a4..777ad9c31 100644 --- a/Src/math.c +++ b/Src/math.c @@ -863,7 +863,7 @@ zzlex(void) p = ptr; ptr = ie; - if (ie - p == 3) { + if (ie - p == 3 && !EMULATION(EMULATE_SH)) { if ((p[0] == 'N' || p[0] == 'n') && (p[1] == 'A' || p[1] == 'a') && (p[2] == 'N' || p[2] == 'n')) { -- cgit v1.2.3