zsh-workers
 help / color / mirror / code / Atom feed
* printf bug(s?)
@ 2005-06-17  0:58 Harald van Dijk
  2005-06-17  8:15 ` Oliver Kiddle
  0 siblings, 1 reply; 6+ messages in thread
From: Harald van Dijk @ 2005-06-17  0:58 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-06-21  9:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-17  0:58 printf bug(s?) Harald van Dijk
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

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).