summary refs log tree commit diff
path: root/Src/prompt.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-08-18 16:20:48 +0100
committerPeter Stephenson <pws@zsh.org>2015-08-18 16:20:48 +0100
commitf8164fb647a8e7947cfde137ddd9517b2fab51c4 (patch)
tree493d0eaddda9ee2e14772282db0a70aa07903cf3 /Src/prompt.c
parent5292d60eb1b2ed5e021e3ee3d05bf08136757ac4 (diff)
downloadzsh-f8164fb647a8e7947cfde137ddd9517b2fab51c4.tar.gz
zsh-f8164fb647a8e7947cfde137ddd9517b2fab51c4.tar.xz
zsh-f8164fb647a8e7947cfde137ddd9517b2fab51c4.zip
36227: attempt to fix metafication problem with ztrftime.
fmt is treated as metafied on entry; use returned length to ensure
we metafy or output the correct length if there are embedded nulls.
Diffstat (limited to 'Src/prompt.c')
-rw-r--r--Src/prompt.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Src/prompt.c b/Src/prompt.c
index 9e8589d5b..be067ee7e 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -271,7 +271,7 @@ static int
 putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 {
     char *ss, *hostnam;
-    int t0, arg, test, sep, j, numjobs;
+    int t0, arg, test, sep, j, numjobs, len;
     struct tm *tm;
     struct timezone dummy_tz;
     struct timeval tv;
@@ -673,12 +673,14 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		     */
 		    for(j = 0, t0 = strlen(tmfmt)*8; j < 3; j++, t0*=2) {
 			addbufspc(t0);
-			if (ztrftime(bv->bp, t0, tmfmt, tm, tv.tv_usec) >= 0)
+			if ((len = ztrftime(bv->bp, t0, tmfmt, tm, tv.tv_usec))
+			    >= 0)
 			    break;
 		    }
 		    /* There is enough room for this because addbufspc(t0)
 		     * allocates room for t0 * 2 bytes. */
-		    metafy(bv->bp, -1, META_NOALLOC);
+		    if (len >= 0)
+			metafy(bv->bp, len, META_NOALLOC);
 		    bv->bp += strlen(bv->bp);
 		    zsfree(tmbuf);
 		    break;