about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2004-05-04 04:17:26 +0000
committerClint Adams <clint@users.sourceforge.net>2004-05-04 04:17:26 +0000
commitc98b9dc800171365eee34a3adbf5a741dbef69ca (patch)
tree7ca4f798e51ff57fd54468e2c951dcc6eef3b55e
parent885509c023dadf766f14c6a51d60048c835e1cd7 (diff)
downloadzsh-c98b9dc800171365eee34a3adbf5a741dbef69ca.tar.gz
zsh-c98b9dc800171365eee34a3adbf5a741dbef69ca.tar.xz
zsh-c98b9dc800171365eee34a3adbf5a741dbef69ca.zip
* 19869: Src/prompt.c, Src/utils.c: avoid segfault when
        prompt-expanding '%D{%p}' or '%D{%P}' under locales with null
        strings for am_pm.
-rw-r--r--ChangeLog6
-rw-r--r--Src/prompt.c4
-rw-r--r--Src/utils.c3
3 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b65843471..d68b7c24d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-05-04  Clint Adams  <clint@zsh.org>
+
+	* 19869: Src/prompt.c, Src/utils.c: avoid segfault when
+	prompt-expanding '%D{%p}' or '%D{%P}' under locales with null
+	strings for am_pm.
+
 2004-05-02  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
 
 	* 19858: Doc/Zsh/options.yo, Src/jobs.c, Src/options.c,
diff --git a/Src/prompt.c b/Src/prompt.c
index 5e80da172..e0304f298 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -528,7 +528,9 @@ putpromptchar(int doprint, int endchar)
 		    tm = localtime(&timet);
 		    for(t0=80; ; t0*=2) {
 			addbufspc(t0);
-			if (ztrftime(bp, t0, tmfmt, tm))
+			if (ztrftime(bp, t0, tmfmt, tm) ||
+			    !strcmp("%P", tmfmt) ||
+			    !strcmp("%p", tmfmt))
 			    break;
 		    }
 		    bp += strlen(bp);
diff --git a/Src/utils.c b/Src/utils.c
index 2e061e591..c0a96a5b4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1831,7 +1831,8 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm)
 		 */
 		*buf = '\0';
 		tmp[1] = fmt[-1];
-		if (!strftime(buf, bufsize + 2, tmp, tm))
+		if (!strftime(buf, bufsize + 2, tmp, tm) &&
+		    tmp[1]!='p' && tmp[1]!='P')
 		    return 0;
 		decr = strlen(buf);
 		buf += decr;