From: "Harald van Dijk" <truedfx@gentoo.org>
To: zsh-workers@sunsite.dk
Subject: printf bug(s?)
Date: Fri, 17 Jun 2005 02:58:35 +0200 [thread overview]
Message-ID: <42B2203B.3060602@gentoo.org> (raw)
Hi,
I'll get right to the point.
1:
When I run the command printf '%', zsh 4.2.5 gives me a segfault. It
should complain that % by itself is invalid instead. I digged around a
bit and it seems to be caused by zsh mistakenly treating '\0' as a valid
flag character. This part is easy enough to work around:
--- zsh-4.2.5.orig/Src/builtin.c
+++ zsh-4.2.5/Src/builtin.c
@@ -3651,7 +3651,7 @@
/* copy only one of each flag as spec has finite size */
memset(flags, 0, sizeof(flags));
- while ((flag = strchr(flagch, *c))) {
+ while (*c!='\0' && (flag = strchr(flagch, *c))) {
if (!flags[flag - flagch]) {
flags[flag - flagch] = 1;
*d++ = *c;
If *c=='\0', strchr doesn't return NULL, but instead, it returns a
pointer to the terminating '\0', so this case should get special treatment.
With this patch, zsh now prints
printf: %: invalid directive
which I consider more sane :-)
But perhaps there's a nicer way to scan for flag characters.
2:
That segfault I noticed when I tried to run printf '\045'. I expected
this to print a single character '%', the same as printf '%%' would. zsh
instead treats it exactly as an ordinary % character. Is this a bug, or
am I wrong to expect it to print '%'? I checked the zsh documentation,
but I couldn't find the answer there. I then checked
http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html
and found
" "\ddd", where ddd is a one, two, or three-digit octal number, shall
be written as a byte with the numeric value specified by the octal
number. "
To me, this seems to mean that it should print just a '%', instead of
converting it to '%' and rereading it, though I may well be misreading
this. (It works as I expected with coreutils's printf, by the way.)
A patch for this is a bit too much for me at the moment though, even
moreso since I'd hate to work on it when it may turn out not to be a
bug, sorry.
Thanks in advance.
next reply other threads:[~2005-06-17 0:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-17 0:58 Harald van Dijk [this message]
2005-06-17 8:15 ` Oliver Kiddle
2005-06-17 13:22 ` Harald van Dijk
2005-06-17 13:48 ` J
2005-06-17 15:47 ` Bart Schaefer
2005-06-21 9:19 ` Oliver Kiddle
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=42B2203B.3060602@gentoo.org \
--to=truedfx@gentoo.org \
--cc=zsh-workers@sunsite.dk \
/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).