From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9201 invoked from network); 17 Jun 2005 13:35:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Jun 2005 13:35:38 -0000 Received: (qmail 84230 invoked from network); 17 Jun 2005 13:35:31 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Jun 2005 13:35:31 -0000 Received: (qmail 2987 invoked by alias); 17 Jun 2005 13:35:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21355 Received: (qmail 2977 invoked from network); 17 Jun 2005 13:35:28 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Jun 2005 13:35:28 -0000 Received: (qmail 83971 invoked from network); 17 Jun 2005 13:35:28 -0000 Received: from smtp.gentoo.org (134.68.220.30) by a.mx.sunsite.dk with SMTP; 17 Jun 2005 13:35:24 -0000 Received: from cp237988-a.mill1.nb.home.nl ([84.29.209.70] helo=[192.168.1.66]) by smtp.gentoo.org with esmtpa (Exim 4.43) id 1DjH0E-0004UU-8U for zsh-workers@sunsite.dk; Fri, 17 Jun 2005 13:35:22 +0000 Message-ID: <42B2CE98.8070905@gentoo.org> Date: Fri, 17 Jun 2005 15:22:32 +0200 From: =?UTF-8?B?SGFyYWxkIHZhbiBExLNr?= User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050428) X-Accept-Language: en-us, en MIME-Version: 1.0 To: zsh-workers@sunsite.dk Subject: Re: printf bug(s?) References: <42B2203B.3060602@gentoo.org> <8037.1118996107@trentino.groupinfra.com> In-Reply-To: <8037.1118996107@trentino.groupinfra.com> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.4 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.4 Oliver Kiddle wrote: > Harald van D?k wrote: > >>When I run the command printf '%', zsh 4.2.5 gives me a segfault. It > > > I can't reproduce the segfault on any system I have access to so perhaps > it is platform specific. Your fix looks right so I'll commit it to > CVS. Thanks. > I`m using a rather plain Linux system (glibc 2,3,5, gcc 3.4.4), and in the end zsh was configured with --prefix=$HOME/zsh --enable-zsh-debug, nothing special. (I'm not sure on the original configuration.) It doesn't always segfault since it depends on whatever happens to be in memory after the format string. A pretty reliable way for me to get it segfaulted is with for x in %; do printf $(echo $x); done on the command line, or much more simply, zsh -c 'printf %'. However, even just entering 'printf %' on the command line segfaulted for me sometimes. Though it doesn't really matter; I guess it's good if you can't reproduce it :) Thanks. >>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 > > > It's not a bug as such. Note that it is entirely consistent with how > printf works from C. I think there was a brief discussion about it when > printf was first added. > > The current implementation makes it easier to share the \ handling code > with echo. It just calls getkeystring() on the whole format > specification first. I seem to remember that, at the time, a survey of > how other printf implementations worked showed a complete mix so it > seemed justifiable to take the lazy option. However, I would agree that > your expected behaviour would probably be better. > Oh, there are other printfs that behave the same? That I didn't know; in that case, I may be better off avoiding using \045 anyway and just replace it with %%... >>" "\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. " > > > It's difficult to know whether it was intended by the wording or not. > > However, that wording also means that \7 should output a bell character > (you need \07 at the moment). Annoyingly, the specification for how \ > escapes work is subtly different for echo and printf. I think \c has a > different definition too. > Ah, right. As another example, \0007 should print a single character with echo, but two ('\0' and '7') with printf '\0007'. However, printf '%b' '\0007' should still print a single character... > So what we probably need to do is have the printf code handle \ escapes > itself at the same time as it scans through the specification looking > for format specifiers. > Either that, or you could modify getkeystring to be able to treat the string the way a printf format string should be treated. That seems to be a bit less work to me. Though, putting it with the % scanning would mean being able to avoid %\nnn... printf '%\0163\n' 'Hello' works right now, and modifying getkeystring would make printf '%\163\n' 'Hello' work. But I'll be happy with whatever you decide to do. > Oliver > > > This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. >