[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf \xNNN
From: |
Jim Meyering |
Subject: |
Re: printf \xNNN |
Date: |
Wed Nov 6 05:12:26 2002 |
Padraig Brady <address@hidden> wrote:
> Why [ :-) ] does printf take up to 3 hex digits?
> What's wrong with 2 (lastest bash just does 2).
>
> $ /usr/bin/printf "\xf73"
> s
> $ printf "\xf73"
> รท3
>
> printf from sh-utils just ignored the first hex digit?
Thank you for the report!
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.
Index: printf.c
===================================================================
RCS file: /fetish/cu/src/printf.c,v
retrieving revision 1.70
diff -u -p -u -p -r1.70 printf.c
--- printf.c 13 Sep 2002 09:50:23 -0000 1.70
+++ printf.c 6 Nov 2002 08:52:59 -0000
@@ -240,11 +240,11 @@ print_esc (const char *escstart)
int esc_value = 0; /* Value of \nnn escape. */
int esc_length; /* Length of \nnn escape. */
- /* \0ooo and \xhhh escapes have maximum length of 3 chars. */
if (*p == 'x')
{
+ /* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits. */
for (esc_length = 0, ++p;
- esc_length < 3 && ISXDIGIT (*p);
+ esc_length < 2 && ISXDIGIT (*p);
++esc_length, ++p)
esc_value = esc_value * 16 + hextobin (*p);
if (esc_length == 0)
@@ -253,6 +253,8 @@ print_esc (const char *escstart)
}
else if (*p == '0')
{
+ /* An octal \0ooo escape sequence has 0 to 3 octal digits
+ after the leading \0. */
for (esc_length = 0, ++p;
esc_length < 3 && isodigit (*p);
++esc_length, ++p)
- Re: printf \xNNN,
Jim Meyering <=