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

Re: Bug#245974: zsh: export LC_ALL=da_DK causes segfault



> Seems that when LC_TIME (or LC_ALL or LANG) is set to a locale such as
> da_DK or de_DE, wherein am_pm is set to null strings, zsh will segfault
> upon prompt-expanding %p or %P.  Seems that the first argument to

So, when am_pm is set to null strings, strftime() with format "%p" or
"%P" will return 0, which zsh is ill-equipped to handle.
The following patch avoids the segfault.  I hope there's a better way to
do this.

Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.15
diff -u -r1.15 prompt.c
--- Src/prompt.c	21 Apr 2004 08:33:37 -0000	1.15
+++ Src/prompt.c	4 May 2004 04:08:54 -0000
@@ -528,7 +528,9 @@
 		    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);
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.58
diff -u -r1.58 utils.c
--- Src/utils.c	25 Mar 2004 12:32:11 -0000	1.58
+++ Src/utils.c	4 May 2004 04:08:55 -0000
@@ -1831,7 +1831,8 @@
 		 */
 		*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;



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