summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-11-22 18:14:13 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-11-22 18:14:13 +0000
commitacbd2ca701ea6b91e3f3a710daa7e32295edc225 (patch)
tree24bc755ed62a06bb383b27ca76b43414c3ae0a59
parent544144debee50937de3bd345b2840c2f864dcb5d (diff)
downloadzsh-acbd2ca701ea6b91e3f3a710daa7e32295edc225.tar.gz
zsh-acbd2ca701ea6b91e3f3a710daa7e32295edc225.tar.xz
zsh-acbd2ca701ea6b91e3f3a710daa7e32295edc225.zip
37191: fix strftime() expansion issue with %p and %P.
In some locales the output from this can validly be empty, so
we need to treat them specially.
-rw-r--r--ChangeLog3
-rw-r--r--Src/utils.c15
2 files changed, 14 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c50e05f8..558af14dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-11-22  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* 37191: Src/utils.c: some locales prduce valid empty output for
+	strtfime escapes %p and %P.
+
 	* 37188: Test/B09hash.ztst: new test.
 
 	* 37187: Src/builtin.c: infinite loop in "hash -m".
diff --git a/Src/utils.c b/Src/utils.c
index 0afa8c908..464097034 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3143,6 +3143,7 @@ strftimehandling:
 		 * in the accounting in bufsize (but nowhere else).
 		 */
 		{
+		    char origchar = fmt[-1];
 		    int size = fmt - fmtstart;
 		    char *tmp, *last;
 		    tmp = zhalloc(size + 1);
@@ -3163,11 +3164,17 @@ strftimehandling:
 		    *buf = '\1';
 		    if (!strftime(buf, bufsize + 2, tmp, tm))
 		    {
-			if (*buf) {
-			    buf[0] = '\0';
-			    return -1;
+			/*
+			 * Some locales don't have strings for
+			 * AM/PM, so empty output is valid.
+			 */
+			if (*buf || (origchar != 'p' && origchar != 'P')) {
+			    if (*buf) {
+				buf[0] = '\0';
+				return -1;
+			    }
+			    return 0;
 			}
-			return 0;
 		    }
 		    decr = strlen(buf);
 		    buf += decr;