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 910DC253B0 for ; Sat, 24 Feb 2024 22:52:09 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1708811529; b=MQ0ty1y81o8sGBQFwNZJnRQLndYu3o0oPHVopaG93uZTy0FvMXk3Xw2xyxjqThFYDrA8OhwmVS qhm7WfmoD/NrCRKUI63aQIyDei6qhlQ9PEieZlHz30rdL5Fy6vskDD6fVTNysy5NfH5pyzuu/8 TAO6ptABdO75wLmpDaFIJXnIYGCJY4Fm/7U/Gmm8Ar1wSJXgRa3ZTlIgsBODY6RDMagzZid99a I0SwLkVMBwcbZcFJDjbLrUUFkBA5ctOWgT0OPwzZDyTwHgFxiZFca57RmqpgchVLAp+sIZ7Ems GVV+UJKxXsdc3mquh/b2SI705fzOob4aWq5C9/wAD6frPg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; 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=1708811529; bh=XOLGmC3eMFjZsmVuS9m9YJ5yS/WK4C6mPGZIdLE0xRg=; 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=L3idDiXVpskPQtgEHT5b5sXi3ZcVDJFAdXHZjm+JFv0XobWfrZ/Vm/xQv1sra5fLlldqmJFF01 eYBhC98KxHoEh3Vbi/wGv+d94TOslZt1SzcC1Wyg5L+nvm5wVk+45pVtsJDe593HcOzdmOgvMz yC5zwcEAwklaPvDvPn8ebb+xuad6xIpWK356Ch8ufGnOr6US47lzCjWVL/PpMGmRosBIMwRjGy jHUNMi++DAGRLF7WsNUajE1FJKHgJeWDmHlkNTLQSRu0zQKE+HRNR6rtkKni1fkHcsNeUSMY06 9KJ3jlNIk4/wvFfXXUglJUUXmWIFEJaDhNwl8Z6Jxu+v5w==; 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=C5FTeXd8YuM0+rzhIezp6NWF9cvEcCTOuzFduHVYC/o=; b=NhZRAvB3wKJY6vQSJ9IUMUjsqW kkrERsrfiZIHIXfLtgIweQnAhqlYha6b02gd+o0wBpH6azBdkP+yYn2r/Og/nFbOBxGJvh9gxjTXg JqYQfSrsubcFNk4V2zl6oSJMiM3sUT0VCms7Hv4/Uf57yj7JRVLjwnJVHph3aiIz87eEM5AEaQZeW mhupZfe8L26E1M25XOEqr1Hev1oEgk1FfQ073PmEoSa3XRfSUCUbfcE3MT3e1lk5vCTS9zsJnzGwJ AADBHviHv4MdVUYOi21NE/lcJnfX0/1EMmig2LCV0h9zxAuTaSuUv0FNlGnJVBLnR0BBiyO+VqLjM wn1ppr6g==; Received: by zero.zsh.org with local id 1rdzwE-000FKy-Ol; Sat, 24 Feb 2024 21:52:06 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; 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-f50.google.com ([209.85.218.50]:42105) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rdzvf-000F1t-EZ; Sat, 24 Feb 2024 21:51:33 +0000 Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a3d5e77cfbeso346605966b.0 for ; Sat, 24 Feb 2024 13:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1708811490; x=1709416290; 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=C5FTeXd8YuM0+rzhIezp6NWF9cvEcCTOuzFduHVYC/o=; b=mtFB+djVbHTLHHmOA5FdpvmFHT0CAxgViNgkWj4IgHlEMDwC0XtAhab2hogjhOIQL8 m4qgCyPIkl8yFqZHJL5jVlUhfDMZnVM6NjUD4Ty7wH5Y8a3umbvgRlwONKwa5qZBf/x8 Fu6Wv5kypKXizoQs66kOOdglcBEUQOygLxuYrwdPSpLSWzUkUzDu7G9mBorVJ3yUW20r M0Zh39WYqb2zul0PIjE5a4unG8yNYQR04xiKXP+bG0NVQ8iGSQRbhd7Cz/GQ7hLoUgml mTGeeoOv8vgRte32eDARSVS/mZ0AJl681LBs563Jktd2MNHgU69GB3BkmGFxkwnXgP3k Xfrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708811490; x=1709416290; 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=C5FTeXd8YuM0+rzhIezp6NWF9cvEcCTOuzFduHVYC/o=; b=c2c1qscnSRvUGjL/5HKR7r2fQ6Urw/wRch5crMthdaVxvypdlUtqmX5+9bTIeDDfYj krnYZBLBi6pTRDXjleSgpgV6ADxB9uhqx1I8NVgkqlkbAYE3Llhdzkl3HST4DKi76Hor VxT2s3z4Sz65qePNP8xDy8ETYhy/jCEok2sF7YUq9F9+i0xZ+8a1S5hbJ2LY/fftF1iX dPf+f+sKtB0zX2JbBQpz+JbuU1qpXParVEU+AzKpk0F0F1+Uyf20pxsX9PRUPCUdVKiG 6nAX0nvHaottN3O0n+LI2yyLVevbydd75Iv98P19gVTFVNubvbWvOvG0bDIKa6FpmT6w RPjA== X-Gm-Message-State: AOJu0YzTCND0pObq0o5RnnkEiK4lVl4R97GmdI8VA8/r810eSjZd2H5v qvpJv7vPVD3prfxCIZ0mr+SpxiszRb89BORKW5ifyoadnB4py8c5Pr4iddZQgaA0PrFww4MokrS CfJtTdEnd7R0SgtBHyAZfipHaLNiFLcYGyS38xEhQqkGn+AQUJA== X-Google-Smtp-Source: AGHT+IFH7XFabYdf2qyASu0rDVxQrG+cf3umAVCaJN7JFaUXGautSKkRu3VKQmPiZU68yBrOUoLgSJ0F8eqd4bQ6mqU= X-Received: by 2002:a17:906:3989:b0:a3e:6bd4:9ac3 with SMTP id h9-20020a170906398900b00a3e6bd49ac3mr2830240eje.11.1708811490004; Sat, 24 Feb 2024 13:51:30 -0800 (PST) MIME-Version: 1.0 References: <20240224144041.7huny3lmihsrokdm@chazelas.org> In-Reply-To: <20240224144041.7huny3lmihsrokdm@chazelas.org> From: Bart Schaefer Date: Sat, 24 Feb 2024 13:51:18 -0800 Message-ID: Subject: Re: Example / partial fix for printf with math expressions To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52593 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: Thanks for the builtin.c patch. Just a couple of notes: On Sat, Feb 24, 2024 at 6:40=E2=80=AFAM Stephane Chazelas wrote (with correction from a later message): > > The math parser seems to work OK with NULs at least in: > > $ typeset -A a > $ let $'a[\0]++' That's not exactly the math parser; mathparse() get as far as noticing it's a parameter reference and then goes through params.c:getnumvalue() which actually does the subscript parsing. You're "cheating" with this construction (and of course "let" is doing the metafication properly to pass the reference through). > $ let $'b =3D (a =3D ##\0) + 32'; echo $a $b For the ## operator the parse is reading just one byte, so you're still not involving anything that might hit a nul-terminated string. This is the math parser and only the math parser, but again with proper metafication: % let $'a\0b =3D 2' zsh: bad math expression: illegal character: \M-C % let $'ab \0 2' zsh: bad math expression: illegal character: \M-C % let $'ab \02' zsh: bad math expression: illegal character: ^B % let $'ab y\02' zsh: bad math expression: operator expected at `y^B' % let $'ab =3D \02' zsh: bad math expression: operand expected at `^B' I'm not sure it's actually very useful to display more than the first character in the latter two cases, but we can try to improve what's currently displayed in multibyte cases. Compare math parser without metafication: % a=3D42 % printf "%d\n" $'a\0b =3D 2' 42 This is what I meant by "stops at NUL". > With and without your example patch applied however: > > $ printf '%d\n' $'a[\0]++' > zsh: invalid subscript That does demonstrate that the length is needed in bin_print() to properly metafy the subscript, yes.