Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
printf bug(s?)
- X-seq: zsh-workers 21352
- From: Harald van Dijk <truedfx@xxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: printf bug(s?)
- Date: Fri, 17 Jun 2005 02:58:35 +0200
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author