From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12491 invoked from network); 17 Jun 2005 00:57:42 -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 00:57:42 -0000 Received: (qmail 14845 invoked from network); 17 Jun 2005 00:57:36 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Jun 2005 00:57:36 -0000 Received: (qmail 27998 invoked by alias); 17 Jun 2005 00:57:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21352 Received: (qmail 27987 invoked from network); 17 Jun 2005 00:57:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Jun 2005 00:57:32 -0000 Received: (qmail 14429 invoked from network); 17 Jun 2005 00:57:32 -0000 Received: from smtp.gentoo.org (134.68.220.30) by a.mx.sunsite.dk with SMTP; 17 Jun 2005 00:57:26 -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 1Dj5Aj-0002TN-77 for zsh-workers@sunsite.dk; Fri, 17 Jun 2005 00:57:25 +0000 Message-ID: <42B2203B.3060602@gentoo.org> Date: Fri, 17 Jun 2005 02:58:35 +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: printf bug(s?) 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.3 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.3 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.