Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Example / partial fix for printf with math expressions
- X-seq: zsh-workers 52587
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Example / partial fix for printf with math expressions
- Date: Fri, 23 Feb 2024 15:23:52 -0800
- Archived-at: <https://zsh.org/workers/52587>
- List-id: <zsh-workers.zsh.org>
No attachment, so beware line wrap.
This repairs (printf "%d" ...) but obviously hasn't touched any of the
several other places where bin_print() calls matheval() and friends.
Upshot, math expects to get metafied strings, bin_print() does not (or
at least not always) pass them that way.
I also did not investigate whether curarg needs a known length rather
than calling metafy with -1, but since math is internally going to
stop at nul bytes anyway, I don't think it matters.
Also because the strings are metafied, checkunary() needs some
MULTIBYTE tweaking to get the count right and not split characters in
the middle when showing an error. Someone who works more with that
should investigate.
diff --git a/Src/builtin.c b/Src/builtin.c
index dd352c146..5fccbac6d 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5465,7 +5465,8 @@ bin_print(char *name, char **args, Options ops, int func)
*d++ = 'l';
#endif
*d++ = 'l', *d++ = *c, *d = '\0';
- zlongval = (curarg) ? mathevali(curarg) : 0;
+ zlongval = (curarg) ?
+ mathevali(metafy(curarg, -1, META_HEAPDUP)) : 0;
if (errflag) {
zlongval = 0;
errflag &= ~ERRFLAG_ERROR;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author