From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29014 invoked from network); 8 Aug 2005 18:14:00 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Aug 2005 18:14:00 -0000 Received: (qmail 10150 invoked from network); 8 Aug 2005 18:13:54 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:13:54 -0000 Received: (qmail 4444 invoked by alias); 8 Aug 2005 18:13:49 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21579 Received: (qmail 4433 invoked from network); 8 Aug 2005 18:13:48 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Aug 2005 18:13:48 -0000 Received: (qmail 9249 invoked from network); 8 Aug 2005 18:13:48 -0000 Received: from mail.gmx.net (213.165.64.20) by a.mx.sunsite.dk with SMTP; 8 Aug 2005 18:13:44 -0000 Received: (qmail invoked by alias); 08 Aug 2005 18:13:43 -0000 Received: from Bc93f.b.pppool.de (EHLO pcdahl4201) [213.7.201.63] by mail.gmx.net (mp034) with SMTP; 08 Aug 2005 20:13:43 +0200 X-Authenticated: #21620914 Message-ID: <024501c59c46$2ae19dc0$cc74fea9@pcdahl4201> From: "Thorsten Dahlheimer" To: Subject: PATCH: Slightly improve printf %s Date: Mon, 8 Aug 2005 20:21:28 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_023D_01C59C56.C1B96380" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Y-GMX-Trusted: 0 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00, MIME_QP_LONG_LINE autolearn=ham version=3.0.4 This is a multi-part message in MIME format. ------=_NextPart_000_023D_01C59C56.C1B96380 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit This change makes it possible to print strings containing NULs with printf '%s', by sharing the code for the %b specifier. After I made this change, the test suite uncovered a bug (which I introduced) in the handling of %b (and now %s) when no argument is left, so the patch includes a fix for that, too. Regards, Thorsten Dahlheimer ------=_NextPart_000_023D_01C59C56.C1B96380 Content-Type: application/octet-stream; name="printf_s.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="printf_s.patch" Index: Src/builtin.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v=0A= retrieving revision 1.143=0A= diff -u -p -r1.143 builtin.c=0A= --- Src/builtin.c 1 Aug 2005 22:20:36 -0000 1.143=0A= +++ Src/builtin.c 8 Aug 2005 15:31:32 -0000=0A= @@ -3752,14 +3752,18 @@ bin_print(char *name, char **args, Optio=0A= print_val(intval);=0A= break;=0A= case 's':=0A= - stringval =3D curarg ? curarg : &nullstr;=0A= - print_val(stringval);=0A= - break;=0A= case 'b':=0A= if (curarg) {=0A= + char *b;=0A= int l;=0A= - char *b =3D getkeystring(metafy(curarg, curlen, META_USEHEAP), &l,=0A= - OPT_ISSET(ops,'b') ? 2 : 0, &nnl);=0A= + if (*c =3D=3D 'b')=0A= + b =3D getkeystring(metafy(curarg, curlen, META_USEHEAP), &l,=0A= + OPT_ISSET(ops,'b') ? 2 : 0, &nnl);=0A= + else {=0A= + b =3D curarg;=0A= + l =3D curlen;=0A= + nnl =3D 0;=0A= + }=0A= /* handle width/precision here and use fwrite so that=0A= * nul characters can be output */=0A= if (prec >=3D 0 && prec < l) l =3D prec;=0A= ------=_NextPart_000_023D_01C59C56.C1B96380--