Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] ztrftime(): Fix truncation for %.
- X-seq: zsh-workers 43940
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: dana <dana@xxxxxxx>
- Subject: Re: [PATCH] ztrftime(): Fix truncation for %.
- Date: Mon, 24 Dec 2018 17:06:01 +0000
- Cc: Zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=fm2; bh=AOL 4oIyR3cJ1rJ/U//9IyhZYWGElcYMaWR2qwwu8/5I=; b=MZwMmHt5kmF1GIVrYMa LlUInSiMZyQxPJNoEq/yxQ0QoDGHTMwGON7/aqG8FebgtzsrVmHgax+pPib0AB4y 2djZ/oCMVagNTQpfmePryLIT1RfBs2+ozQttSszAgXiDCHSPwTllXt2lXtXpqc1v RSH2rW+bG4D4o89QjbvSMWTNWIyKbU1rW5ToooaeWmjcNISK7xzEtgW10XaRJI5r lBFvLnG2ARWQZU2MAMYXcDwNbvNvUcAzQHyXQoqIhkxez8sbnkByi7IenZ4bd8vu Gd0kMWPQZnYU/XvRFhn3mGBn9oZCrwDmyLHI2Jd+yp6arW6cizWJLBSuzISVX4fv 5cA==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=AOL4oI yR3cJ1rJ/U//9IyhZYWGElcYMaWR2qwwu8/5I=; b=ab7IaAV/9tT/cJjrPj7B6R +UaPmamEdqUBOwUOddw5W4V7qpy8IY3oYmUPh87Z29cOLywqsfemyZYFohGkHIFJ AaC+DUNHWdYFM2uTcn4Eqa/6F1e3uTtJZe1oZ//ohHv/TzzhfzJKAZOW+XjtPrwk aMK9D8t7l1M24oKiSBJPlbULYmjr274RD4Hwtsa0OlHETMBKHA3KoAXaHITPMZ6o R1+YWPkw6qN5NGFTp2vxRGuU0eenSoHNujJemf2KIZQKIWxJj2hvhJlUP2IswSAL PNLo9Awl03nVmcnYwbaXp9bv02MXPa/TOIvlnnoIXtyVEuuwPWf2t4JV0Z1E7moQ ==
- In-reply-to: <4E316F0B-5606-4E93-8988-28A5444612E6@dana.is>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <d7b0451f90bdfe61f48cc1361690180e07158900.camel@ntlworld.com> <20181224054021.GK1941@sym.noone.org> <20181224071421.GL1941@sym.noone.org> <C7926210-86FE-4626-9A93-4A387C315CC4@dana.is> <C910A9B2-EFC0-49CC-B980-38127CC81175@dana.is> <1545655545.1499531.1617344072.151563DD@webmail.messagingengine.com> <4E316F0B-5606-4E93-8988-28A5444612E6@dana.is>
dana wrote on Mon, Dec 24, 2018 at 10:24:16 -0600:
> On 24 Dec 2018, at 06:45, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >Shouldn't the former print [124]?
>
> No, %. only uses the nanoseconds value given to ztrftime(), which is
> implicitly 0 in the former case. It's not substituting an arbitrary series of
> inputs in the style of printf, it only takes those two time arguments to
> ztrftime().
D'oh, thanks.
> +++ b/Src/utils.c
> @@ -3334,19 +3334,22 @@ morefmt:
> #endif
> switch (*fmt++) {
> case '.':
> + {
> if (digs > 9)
> digs = 9;
> + if (ztrftimebuf(&bufsize, digs))
> + return -1;
> + long fnsec = nsec;
> if (digs < 9) {
> int trunc;
> for (trunc = 8 - digs; trunc; trunc--)
> + fnsec /= 10;
> + fnsec = (nsec < 999999500 ? (fnsec + 5) : fnsec) / 10;
> }
Why the magic number 999999500? Why not 999999950 or 999995000 or
99950? And why would it a problem to add 5 when nsec=999999500?
> + sprintf(buf, "%0*ld", digs, fnsec);
> buf += digs;
> break;
> + }
> case '\0':
> /* Guard against premature end of string */
> *buf++ = '%';
Messages sorted by:
Reverse Date,
Date,
Thread,
Author