zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] fix strftime builtin (on Cygwin)
@ 2017-03-01 10:38 Jun T.
  0 siblings, 0 replies; only message in thread
From: Jun T. @ 2017-03-01 10:38 UTC (permalink / raw)
  To: zsh-workers

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 
        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))
 
     len = 0;
     for (x=0; x < 4; x++) {
-        if ((len = ztrftime(buffer, bufsize, argv[0], t, 0L)) >= 0)
+        if ((len = ztrftime(buffer, bufsize, argv[0], t, 0L)) >= 0 || x==3)
 	    break;
 	buffer = zrealloc(buffer, bufsize *= 2);
     }
-    DPUTS(len < 0, "bad output from ztrftime");
+    if (len < 0) {
+	zwarnnam(nam, "bad/unsupported format: '%s'", argv[0]);
+	zfree(buffer, bufsize);
+	return 1;
+    }
 
     if (scalar) {
 	setsparam(scalar, metafy(buffer, len, META_DUP));



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-01 11:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-01 10:38 [PATCH] fix strftime builtin (on Cygwin) Jun T.

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).