zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Example / partial fix for printf with math expressions
Date: Fri, 23 Feb 2024 15:23:52 -0800	[thread overview]
Message-ID: <CAH+w=7Z+vjX7sAgajLsQJw2KkZtyvaZvvJ+-=-7rMFH7p9+j7g@mail.gmail.com> (raw)

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;


             reply	other threads:[~2024-02-23 23:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 23:23 Bart Schaefer [this message]
2024-02-24 14:40 ` Stephane Chazelas
2024-02-24 15:10   ` Stephane Chazelas
2024-02-24 21:51   ` Bart Schaefer
2024-02-25  6:54   ` Stephane Chazelas
2024-02-26  0:04     ` Bart Schaefer
2024-02-26 17:12       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Z+vjX7sAgajLsQJw2KkZtyvaZvvJ+-=-7rMFH7p9+j7g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).