Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: ztrftime: more workarounds for broken strftime interface
- X-seq: zsh-workers 37195
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: ztrftime: more workarounds for broken strftime interface
- Date: Sun, 22 Nov 2015 18:43:49 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=HhLrrtf/ZryBQVyP/mRZ0PO8JT45vOGpmVNAFpTwsjI=; b=zP4gh3Z1/VVT5zCBsL0YDy50qAtnGBlHGws0o1S58apxC257D5E1iQycRqnZzU5plk tZFBbzy4KCDenaURnAV8Eb3VmiE2ZeeFkmO0RRCRAsRmtwP2xToppWt7Nr7sNjUAu+ev UFxpaGUfr3nXkgx02iCqtVM/X0AdWJzkCV2uMGShA/Nd1uF6d0bTykCOQcVABqk2x5J2 0NE2A2sC7qxx4W/sXH4zaDBg6L2lHPZ2KGmg+ZCkxuBrFflDAqO77lYoQKzKiXWbVvRK JqeBoOcBO9TZicbWdOl5CS2L5g9u4dk7RvfuiljZwE1UOLwkNur9wL3ctur5yjdPn/Ct 2Y0w==
- In-reply-to: <151122092711.ZM10012@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <151122092711.ZM10012@torch.brasslantern.com>
On Sun, Nov 22, 2015 at 6:27 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Do we want to try to fix users/20859 ? It shouldn't be that hard for
> someone in an environment where it fails (I'm having trouble creating
> one).
The problem is that the strftime() function is defined by an idiot. There
is no way to differentiate the success of a zero-length result and any
error. If there is any error then the return result is undefined so we
cannot use it.
I guess we could append some fixed string always, and then discard this
string, for example an x character.
This somehow works and doesn't break the tests, nor my prompt.
---
Src/utils.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/Src/utils.c b/Src/utils.c
index c19cca8..f42b25b 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3154,8 +3154,9 @@ strftimehandling:
{
int size = fmt - fmtstart;
char *tmp, *last;
- tmp = zhalloc(size + 1);
+ tmp = zhalloc(size + 2);
strncpy(tmp, fmtstart, size);
+ tmp[size] = 'x';
last = fmt-1;
if (*last == Meta) {
/*
@@ -3168,7 +3169,7 @@ strftimehandling:
*/
*last = *++fmt ^ 32;
}
- tmp[size] = '\0';
+ tmp[size+1] = '\0';
*buf = '\1';
if (!strftime(buf, bufsize + 2, tmp, tm))
{
@@ -3178,7 +3179,7 @@ strftimehandling:
}
return 0;
}
- decr = strlen(buf);
+ decr = strlen(buf) - 1;
buf += decr;
bufsize -= decr - 2;
}
--
2.6.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author