mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-05-22 00:11:30 +02:00
52597: fix character counts in context of operator and operand errors
This commit is contained in:
parent
69c0c646bb
commit
6c50d15562
2 changed files with 21 additions and 7 deletions
|
@ -1,5 +1,8 @@
|
|||
2024-02-24 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 52597: Src/math.c: fix multibyte and metafied character counts
|
||||
when providing context for operator and operand errors
|
||||
|
||||
* 52596: Src/exec.c: metafy interpreter name for error message
|
||||
|
||||
* Stephane: 52591: Src/builtin.c: printf builtin must pass
|
||||
|
|
25
Src/math.c
25
Src/math.c
|
@ -1557,21 +1557,32 @@ checkunary(int mtokc, char *mptr)
|
|||
errmsg = 2;
|
||||
}
|
||||
if (errmsg) {
|
||||
int len, over = 0;
|
||||
int len = 0, over = 0;
|
||||
char *errtype = errmsg == 2 ? "operator" : "operand";
|
||||
while (inblank(*mptr))
|
||||
mptr++;
|
||||
len = ztrlen(mptr);
|
||||
if (len > 10) {
|
||||
len = 10;
|
||||
over = 1;
|
||||
if (isset(MULTIBYTE))
|
||||
MB_CHARINIT();
|
||||
while (over < 10 && mptr[len]) {
|
||||
if (isset(MULTIBYTE))
|
||||
len += MB_METACHARLEN(mptr+len);
|
||||
else
|
||||
len += (mptr[len] == Meta ? 2 : 1);
|
||||
++over;
|
||||
}
|
||||
if ((over = mptr[len])) {
|
||||
mptr = dupstring(mptr);
|
||||
if (mptr[len] == Meta)
|
||||
mptr[len+1] = 0;
|
||||
else
|
||||
mptr[len] = 0;
|
||||
}
|
||||
if (!*mptr)
|
||||
zerr("bad math expression: %s expected at end of string",
|
||||
errtype);
|
||||
else
|
||||
zerr("bad math expression: %s expected at `%l%s'",
|
||||
errtype, mptr, len, over ? "..." : "");
|
||||
zerr("bad math expression: %s expected at `%s%s'",
|
||||
errtype, mptr, over ? "..." : "");
|
||||
}
|
||||
unary = !(tp & OP_OPF);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue