From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1420 invoked by alias); 1 Mar 2017 11:15:10 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40681 Received: (qmail 4680 invoked from network); 1 Mar 2017 11:15:10 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-mqugw.biglobe.ne.jp by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(133.208.100.1):SA:0(-0.7/5.0):. Processed in 0.709295 secs); 01 Mar 2017 11:15:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spf01.biglobe.ne.jp designates 133.208.100.1 as permitted sender) X-Biglobe-Sender: From: "Jun T." Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: [PATCH] fix strftime builtin (on Cygwin) Message-Id: <99DF3652-F6D9-41C9-AC45-AAC900F1DD6A@kba.biglobe.ne.jp> Date: Wed, 1 Mar 2017 19:38:59 +0900 To: "zsh-workers@zsh.org" Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) X-Mailer: Apple Mail (2.1510) X-Biglobe-Spnum: 53527 On Cygwin, V09datetime.ztst gives (built with --zsh-debug) 9: datetime.c:140: bad output from ztrftime (eval):9: write error: bad address The 'write error' is rather serious, and if I manually run zsh% strftime '%^_10B' 0 then it hangs after producing lots of bogus output. On many systems, if strftime(3) doesn't understand the format then it just copies the format to the output buffer. On Cygwin, on the other = hand, strftime() returns 0 without modifying the buffer. ztrftime() then = returns -1 and 'len' is set to -1 (datetime.c:136). Using this negative len in=20 fwrite(buffer, 1, len, stdout); (datetime.c:145) causes the problem. diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index bb82c54..6e9047b 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -133,11 +133,15 @@ output_strftime(char *nam, char **argv, Options = ops, UNUSED(int func)) =20 len =3D 0; for (x=3D0; x < 4; x++) { - if ((len =3D ztrftime(buffer, bufsize, argv[0], t, 0L)) >=3D 0) + if ((len =3D ztrftime(buffer, bufsize, argv[0], t, 0L)) >=3D 0 = || x=3D=3D3) break; buffer =3D zrealloc(buffer, bufsize *=3D 2); } - DPUTS(len < 0, "bad output from ztrftime"); + if (len < 0) { + zwarnnam(nam, "bad/unsupported format: '%s'", argv[0]); + zfree(buffer, bufsize); + return 1; + } =20 if (scalar) { setsparam(scalar, metafy(buffer, len, META_DUP));