From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: ztrftime: more workarounds for broken strftime interface
Date: Sun, 22 Nov 2015 18:43:49 +0100 [thread overview]
Message-ID: <1448214229-11380-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <151122092711.ZM10012@torch.brasslantern.com>
On Sun, Nov 22, 2015 at 6:27 PM, Bart Schaefer <schaefer@brasslantern.com> 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
next prev parent reply other threads:[~2015-11-22 18:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-22 17:27 Fix strftime (prompts) before 5.2? Bart Schaefer
2015-11-22 17:43 ` Mikael Magnusson [this message]
2015-11-22 18:06 ` Peter Stephenson
2015-11-22 18:38 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448214229-11380-1-git-send-email-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).