zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var})
Date: Sat, 24 Feb 2024 18:17:42 -0800	[thread overview]
Message-ID: <CAH+w=7b0GYtGChO=vOUqO8MEkysi7TmxCUhdW=GRxWqYFaBHjw@mail.gmail.com> (raw)
In-Reply-To: <20240224094722.hnullrzrb6gsswnm@chazelas.org>

On Sat, Feb 24, 2024 at 1:47 AM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> 2024-02-23 14:32:49 -0800, Bart Schaefer:
> [...]
> > More relevant to this discussion is that math errors are one of the
> > two existing callers using the %l format, so any attempt to improve
> > this is going to require changing those calls anyway.
>
> I don't see why we'd need to change the call to zerr in those
> cases. Just fix printf.

That doesn't resolve the issue that math.c:checkunary() is
miscalculating the truncation width even before calling zerr().

Having looked more closely now, if I fix that calculation, then
checkunary() can do the truncation itself and doesn't need to use %l
any longer.

> But in the case of ${var?err}, the err is already metafied, so
> if you make %l take unmetafied input, you're just moving the
> unmetafication to the caller which is counterproductive as it
> makes it break on NULs.

No, it doesn't make it break on NULs, because unmetafy() returns the
length of the resulting string including the NULs, which we can then
pass down to zerr().

The actual tradeoff to make %l do the raw output is:
+ fix the width calculation in math.c, then use %s *
+ add one call to metafy() in parse.c, to use %s instead of %l **
+ add one call to unmetafy() in subst.c, to use %l instead of %s
- remove metalen(), zhalloc(), memcpy(), and nicezputs() from utils.c
+ add one call to fwrite() in place of the above

* Which we should do anyway, so not really a tradeoff
** It's not even certain that's required, given that we're outputting
a string from the lexer

> Also %l is intended (at least in the one case I saw it used) to
> truncase user input, so it should be nicezputs'ed.

Unfortunately it's used *incorrectly* to truncate user input at that one place.

> To me, the only things to do are:
>
> 1. add a %S for raw output (expects metafied input like
>    everything else) to tbe used by ${var[:]?error} and likely only
>    those.

That adds another branch in utils.c with at least the same unmetafy()
+ fwrite(), instead of removing code that the callers no longer need.

> 2. Add missing metafy in bin_print (and possibly elsewhere)
>    before calling the math parser

Needed either way.

> 3. Fix those cases where zerrmsg is called with %s/%l/%S
>    arguments non-metafied like in that "bad interpreter" case
>    above.

That's a whack-a-mole hunt and also orthogonal to whether or not to add %S.

> 4. (optional): Improve %l usages to truncate based on number of
>    characters rather than bytes or at least avoid cutting
>    characters in the middle.

Not needed.


  parent reply	other threads:[~2024-02-25  2:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13  8:02 $var not expanded in ${x?$var} Stephane Chazelas
2023-01-16  8:35 ` Daniel Shahaf
2023-01-16 17:15 ` Peter Stephenson
2024-02-20  7:05   ` Stephane Chazelas
2024-02-20 17:45     ` Bart Schaefer
2024-02-20 19:39       ` Stephane Chazelas
2024-02-21  4:44         ` Bart Schaefer
2024-02-21 19:45           ` Stephane Chazelas
2024-02-21 19:52             ` Bart Schaefer
2024-02-21 20:21               ` Stephane Chazelas
2024-02-22  0:46                 ` [PATCH] unmetafy " Bart Schaefer
2024-02-22  7:23                   ` Stephane Chazelas
2024-02-22  7:55                     ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Stephane Chazelas
2024-02-22 17:02                       ` Bart Schaefer
2024-02-22 22:31                         ` Bart Schaefer
2024-02-23  0:49                           ` Bart Schaefer
2024-02-23 19:27                           ` Stephane Chazelas
2024-02-23 22:32                             ` Bart Schaefer
2024-02-23 23:38                               ` Bart Schaefer
2024-02-24  9:47                               ` Stephane Chazelas
2024-02-24 10:36                                 ` Stephane Chazelas
2024-02-25  4:35                                   ` [PATCH] 'bad interpreter' error garbled Bart Schaefer
2024-02-25  5:26                                     ` Bart Schaefer
2024-02-25  2:17                                 ` Bart Schaefer [this message]
2024-02-25  6:05                                   ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  7:29                                     ` Stephane Chazelas
2024-02-25  8:28                                       ` typeset -<non-ASCII> (Was: metafication in error messages) Stephane Chazelas
2024-02-25  8:35                                         ` Stephane Chazelas
2024-02-25 21:02                                         ` Bart Schaefer
2024-02-23  0:33                       ` Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) Bart Schaefer
2024-02-25  5:06                       ` [PATCH] count multibyte and metafied characters correctly for math ops errors Bart Schaefer
2024-02-22  8:34                     ` [PATCH] unmetafy Re: $var not expanded in ${x?$var} Roman Perepelitsa
2024-02-22 17:07                       ` 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=7b0GYtGChO=vOUqO8MEkysi7TmxCUhdW=GRxWqYFaBHjw@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).