bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

builtin printf "\0000" only prints 1 byte


From: llattanzi+bash
Subject: builtin printf "\0000" only prints 1 byte
Date: Mon, 21 Jun 2004 18:43:47 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: darwin8.0
Compiler: gcc
Compilation CFLAGS: -arch i386 -arch ppc -g -Os -pipe -no-cpp-precomp -arch i386 -arch ppc -pipe -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' -DCONF_OSTYPE='darwin8.0' -DCONF_MACHTYPE='powerpc-apple-darwin8.0' -DCONF_VENDOR='apple' -DSHELL -DHAVE_CONFIG_H -DMACOSX -I. -I/SourceCache/bash/bash-30/bash -I/SourceCache/bash/bash-30/bash/include -I/SourceCache/bash/bash-30/bash/lib -arch i386 -arch ppc -g -Os -pipe -no-cpp-precomp -arch i386 -arch ppc -pipe uname output: Darwin stderr.apple.com 8.0.0b1 Darwin Kernel Version 8.0.0b1: Mon May 10 23:45:14 PDT 2004; root:xnu/xnu-600.3.obj~4/RELEASE_PPC Power Macintosh powerpc
Machine Type: powerpc-apple-darwin8.0

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        printf "\0000" should print '\0' and '0'

Repeat-By:
        printf "\0000" | od -c
        compare against /usr/bin/printf

Fix:
Index: printf.def
===================================================================
RCS file: /cvs/root/bash/bash/builtins/printf.def,v
retrieving revision 1.1.1.5
diff -u -d -b -w -r1.1.1.5 printf.def
--- printf.def  2003/04/05 08:00:28     1.1.1.5
+++ printf.def  2004/06/22 01:41:38
@@ -105,7 +105,7 @@

 static void printf_erange __P((char *));
 static void printstr __P((char *, char *, int, int, int));
-static int tescape __P((char *, int, char *, int *));
+static int tescape __P((char *, int, char *, int *, int));
 static char *bexpand __P((char *, int, int *, int *));
 static char *mklong __P((char *, char *, size_t));
 static int getchr __P((void));
@@ -188,7 +188,7 @@
              fmt++;
              /* A NULL fourth argument to tescape means to not do special
                 processing for \c. */
-             fmt += tescape (fmt, 1, &nextch, (int *)NULL);
+             fmt += tescape (fmt, 1, &nextch, (int *)NULL, 0);
              putchar (nextch);
              fmt--;    /* for loop will increment it for us again */
              continue;
@@ -540,13 +540,16 @@
value. *SAWC is set to 1 if the escape sequence was \c, since that means to short-circuit the rest of the processing. If SAWC is null, we don't do the \c short-circuiting, and \c is treated as an unrecognized escape
-   sequence.  */
+   sequence.
+ %b format must handle \\0[0-7]{1,3} but printf fmt must only handle \\[0-7]{1,3} + Use incoming parameter to print \0000 differently for each caller. */
 static int
-tescape (estart, trans_squote, cp, sawc)
+tescape (estart, trans_squote, cp, sawc, b_format)
      char *estart;
      int trans_squote;
      char *cp;
      int *sawc;
+     int b_format;
 {
   register char *p;
   int temp, c, evalue;
@@ -583,7 +586,11 @@
         sequences are supported as well. */
       case '1': case '2': case '3': case '4':
       case '5': case '6': case '7':
-       for (temp = 2+(c=='0'), evalue = c - '0'; ISOCTAL (*p) && temp--; p++)
+        if (b_format)
+         temp = 2+(c=='0');
+        else
+          temp = 2;            /* limit to \000 not \0000 like %b */
+       for (evalue = c - '0'; ISOCTAL (*p) && temp--; p++)
          evalue = (evalue * 8) + OCTVALUE (*p);
        *cp = evalue & 0xFF;
        break;
@@ -657,7 +664,7 @@
          continue;
        }
       temp = 0;
-      s += tescape (s, 0, &c, &temp);
+      s += tescape (s, 0, &c, &temp, 1);
       if (temp)
        {
          if (sawc)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]