From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 2A348285BE for ; Sun, 25 Feb 2024 03:18:32 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1708827512; b=TCcD01DvWsBHFIuDY3oLy8zktTW5Mg7o1Wq2XXy+c+GjN6zmRp7CjWXXl9o0l/DdAMt53lLf2F hZZiShSZWZbHKt2jEFpWbJB1373GsvM550gEqx7L0vY9N4d6JZP7TBzfynt84svbYUyDd7v6CY G1repybYZ1RadB/aBVeXregdWNAyb3g5jh0oL/Oxo4vZnY2b+o0nILKdcjSRSFnoxwAA2mTuyo Ec5MChT5OWAE3jgKFf4wDNsfAhx9z/cBP4VtpGvbV09uf6fxvjNaoXWQlXgmiatH1uvq2gD2E0 Ug6fR2IYLcqaL6JNpi8Mh7lErAHzWR2UVkTVlt1kBlbUQw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f45.google.com) smtp.remote-ip=209.85.218.45; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1708827512; bh=7sj8ttuHv3kAXLODg7KKgCqIXYZqg2Onfy4liuYtIVc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=O+Vedz35wfLO/6srDE5ZFQR5UTjjxBNZP6CA9fGOuqF2EJ78R5rJDvDyvDqo2EeCtDw2W3Un+d 7eCKWkwxQMBBGqFK4eo+geUnBSq9plJd7ETjwXtpX9an9PWPLKrkHXKRxzsTd/licIg1qSCC5C ahh4cwU6Xrk2xOOASFz3NImORDJv6qilqF4TgMJDNY7G10Zht/DRcOvruE8lSjE/7k0iAfgIjv KdOM8k+J2zFQhEntn5+Q68FBF5D2qMlq7mkGK4kkAJaQcklJm0GxSQFS2WBVi8yUwy+EoXVyR3 p+FrXHIScH+23sRlRM0aytiE7J+r3n5ueOtn2CaLjIwRLA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=jjgx2D39Kd+cg94L6H0QsOLDC4lOJ3oVKRpXWEQtf9g=; b=ameFD2EchNhh6jyOaWnY5OkuKa LTZy0YFtTLWq+xBEqD/10XHskWD+WXh/5jYJ7AXOuiqP5ruINKSZ6lEzrE4PwGOrpwhFGQ7Wxgybe oBIKhJAxg/IXjtfbct+XuICE1U3patYdvb4ujIMdP7r2yCJz7NHahGTeeg3/Yi8wD8wNSOdsODxrm 3RHLwmGD2ZtV3JOq+ngYlPgyIgAwkvMS7TTu+TNUg7D60pHXYEIgiLqKxPryN/XowSfMrZbk1ckzn ayAe0i7DjtgmIixm/oPggjgDmJXGtvktAGxbl3HcCMK8hgCq381rumHcuIqaKQxS1W0O6BtZLTeXt RwpU6ZpQ==; Received: by zero.zsh.org with local id 1re463-000MmF-NG; Sun, 25 Feb 2024 02:18:31 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f45.google.com) smtp.remote-ip=209.85.218.45; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f45.google.com ([209.85.218.45]:57401) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1re45S-000MTt-Jt; Sun, 25 Feb 2024 02:17:56 +0000 Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a36126ee41eso212330966b.2 for ; Sat, 24 Feb 2024 18:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1708827474; x=1709432274; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jjgx2D39Kd+cg94L6H0QsOLDC4lOJ3oVKRpXWEQtf9g=; b=PSpMhKf1x3rZFiAzSbHV08nEZF9z+514m3CaBgcTAXWUVXsQlRBWMzLyxHcDMcYMe5 r+mTQS2rRTcPQLqc95tBuroMPgMaWtq8rtjfTGX79lA4CAYz0XMg2OGD/x4JuRUgNz8m tdUEahDFm802LG6I1fcHPXozKjcBxGfcA9VYWip8C8ddXjS2sZCznCwtsUTPcPq7sXPp rK8EvPjhc2A+4ELGHhaTp966YgdbhFVCjqi24z0BbinEd071/9QCJU5bC4ils5DAo2om LRXT9bH7W/UNu786KuKWnSEvhHguutHmP2ZWZciF8A6kQRgrXlXYMw6wRLbYh24rW5RC Z2KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708827474; x=1709432274; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jjgx2D39Kd+cg94L6H0QsOLDC4lOJ3oVKRpXWEQtf9g=; b=Q6R8T+BHKdRpAQS8ifduSYe90klp4kKFwfPaUjx0L/XGvKhcBi4BEvY+MoNMgwtQgz 3mRwuD6Jc9WndVZD/CfELr75XEClRGk5PFTROO4bdCmfGVfSwaDIoio3ydjFCt2JQvam hr3FRlwDBKj86nVIeu+qS/6GWoOMSBGkz6e3+VDhQLGPKwKbK4nom6FenPA0BaDRqwcy f9N5bjM2imc3miPNzsTygRwISU6vBeJr3vTF6f3I2J03ZK/3n+iBqLofph6hGaxVEZUl gbRdhtZkO4UBFxARBHVAwRpHveg1ndbm6jyqA6PJDs1eZ2IqMCt/amJjxPjV7iT9Lgr3 cKkg== X-Gm-Message-State: AOJu0YzxKTgKHB4Y+ArLdEhgMOWZmJmCUZWe8vLjUlnrFmW/5XL/Zjyi ZUHVuFZYvaN2WZ7oEHm/lRqGh3m9O4ymVad3/j0GVY7aJZ95wEVfH/O4uZv5wwpCXJRl5F7ix36 cb2OrB16C8jWyHMhbKWXMOtmje4vMwtZpTv/z+OroBmJlvgSeIg== X-Google-Smtp-Source: AGHT+IGshKntTXubcCsIBcA/BEae0dQWKvmX7KeYQhK5QOAyUiazy7qz80OHbe4L0kQyl4yIJ0p51Xy2OUQRb9HR/LA= X-Received: by 2002:a17:906:b14d:b0:a3e:58df:fb08 with SMTP id bt13-20020a170906b14d00b00a3e58dffb08mr2159033ejb.44.1708827473801; Sat, 24 Feb 2024 18:17:53 -0800 (PST) MIME-Version: 1.0 References: <20240221194534.o2mufin7orng6ttg@chazelas.org> <20240221202150.tccftcqbxqqexq4x@chazelas.org> <20240222072313.7woy5vxvt4fbxyhj@chazelas.org> <20240222075528.eruaoosiuhmcrdsy@chazelas.org> <20240223192717.tczrbc63fei7d4m2@chazelas.org> <20240224094722.hnullrzrb6gsswnm@chazelas.org> In-Reply-To: <20240224094722.hnullrzrb6gsswnm@chazelas.org> From: Bart Schaefer Date: Sat, 24 Feb 2024 18:17:42 -0800 Message-ID: Subject: Re: Metafication in error messages (Was: [PATCH] unmetafy Re: $var not expanded in ${x?$var}) To: zsh workers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52595 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sat, Feb 24, 2024 at 1:47=E2=80=AFAM Stephane Chazelas 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 pl= ace. > 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.