|
Re: printf \xNNN: msg#00097gnu.core-utils.bugs
Paul Eggert <eggert@xxxxxxxxxxx> wrote: >> 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. Hi Paul, Thank you for the patch. However, I was surprised to see that according to POSIX, http://www.opengroup.org/onlinepubs/007904975/utilities/printf.html printf does not recognize hexadecimal constants: Hexadecimal character constants as defined in the ISO C standard are not recognized in the format operand because there is no consistent way to detect the end of the constant. Octal character constants are limited to, at most, three octal digits, but hexadecimal character constants are only terminated by a non-hex-digit character. In the ISO C standard, the "##" concatenation operator can be used to terminate a constant and follow it with a hexadecimal character to be written. In the shell, concatenation occurs before the printf utility has a chance to parse the end of the hexadecimal constant. The current implementation is consistent (at least in this respect) with the one in bash's built-in printf command, so I think it's best to leave it the way it is, at least for the upcoming coreutils-5.0. What do you think? Also, if coreutils' printf does eventually accept arbitrarily long hexadecimal character constants, it should warn when the value would be out of range, and should probably align with the C behavior of ignoring all but the last two hex digits. > 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 Thanks! I've fixed those formatting bugs. > didn't do this (sorry, I've gotta run....). > > 2003-03-24 Paul Eggert <eggert@xxxxxxxxxxx> > > * 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. |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: printf \xNNN: 00097, Paul Eggert |
|---|---|
| Next by Date: | Re: bug: printf overruns an argument: 00097, Jim Meyering |
| Previous by Thread: | Re: printf \xNNNi: 00097, Paul Eggert |
| Next by Thread: | Re: printf \xNNN: 00097, Paul Eggert |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |