Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] fix strftime builtin (on Cygwin)



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




Messages sorted by: Reverse Date, Date, Thread, Author