bug-coreutils
[Top][All Lists]
Advanced

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

Re: printf \xNNN


From: Paul Eggert
Subject: Re: printf \xNNN
Date: Mon, 24 Mar 2003 16:44:08 -0800 (PST)

> From: Jim Meyering
> Date: Wed Nov 6 05:12:26 2002

> That looks like a bug.  It is at least 10 years old, since that code
> was there for my initial cvs import on Nov 1, 1992.

I don't think it's a bug, since it's how printf behaves in the C language.
For example, if I write this program:

        #include <stdio.h>
        int main (void)
        {
          return printf ("(\x00000040)\n");
        }

the output is "(@)".  The GNU coreutils manual says that GNU printf is
supposed to behave like the C printf function, so I'd say that the
1992 behavior was correct.

Here is a proposed patch to revert the behavior, and fix some texinfo
formatting bugs.  You also need to remove tests/misc/printf-hex, but I
didn't do this (sorry, I've gotta run....).

2003-03-24  Paul Eggert  <address@hidden>

        * doc/coreutils.texi (printf invocation): \x can take any
        number of digits.
        * src/printf.c (print_esc): Implement this.
        This undoes the 2002-11-06 patch.

--- doc/coreutils.texi  2003/03/13 13:15:50     4.5.11.0
+++ doc/coreutils.texi  2003/03/25 00:41:18     4.5.11.1
@@ -8454,12 +8454,14 @@ all of the given @var{argument}s.
 argument string with @samp{\} escapes interpreted in the same way as in
 the @var{format} string.
 
address@hidden \0ooo
address@hidden \xhh
address@hidden interprets @samp{\0ooo} in @var{format} as an octal number
-(if @var{ooo} is 0 to 3 octal digits) specifying a character to print,
-and @samp{\xhh} as a hexadecimal number (if @var{hh} is 1 to 2 hex
-digits) specifying a character to print.
address@hidden address@hidden
address@hidden address@hidden
+
address@hidden interprets @address@hidden in @var{format} as an
+octal number (if @var{ooo} is 1 to 3 octal digits) specifying a the
+numeric code of a character to print, and @address@hidden as a
+hexadecimal number (if @var{hh} is 1 or more hexadecimal digits)
+specifying the numeric code of a character to print.
 
 @kindex \uhhhh
 @kindex \Uhhhhhhhh
--- src/printf.c        2003/03/25 00:17:55     4.5.11.4
+++ src/printf.c        2003/03/25 00:28:22     4.5.11.5
@@ -245,9 +245,8 @@ print_esc (const char *escstart)
 
   if (!posixly_correct && (*p == 'x'))
     {
-      /* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits.  */
       for (esc_length = 0, ++p;
-          esc_length < 2 && ISXDIGIT (*p);
+          ISXDIGIT (*p);
           ++esc_length, ++p)
        esc_value = esc_value * 16 + hextobin (*p);
       if (esc_length == 0)




reply via email to

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