On Sun, 2021-04-18 at 11:17 -0900, Philip Guenther wrote:
> 
> I'll just throw in a note that the current POSIX spec does not include 
> support for \x in the printf(1) format or in the argument to the %b format 
> specifier.  At least for \x in the format string it
> appears to require that it _not_ be interpreted, such that
>     printf '\x61\n'
> must output
>     \x61
>  and not
>     a

Could you point out where it states that an escape-sequence not
specified must output the original text? The way I read it[0][1]:

In addition to the escape sequences shown in XBD File Format Notation (
'\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v' ), "\ddd", where ddd is a
one, two, or three-digit octal number, shall be written as a byte with  
the numeric value specified by the octal number.

and

Escape Sequences and Associated Actions lists escape sequences and
associated actions on display devices capable of the action.

both don't specify what happens on \<something else>. So unless I missed
something I'd say it is unspecified and up for greps. Note that
we/NetBSD have this behaviour since 1993 and gprintf also has it; I'm
just trying to make our current implementation suck a little less.
> 
> FreeBSD 12's /usr/bin/printf does this, for example, however at least some on 
> the list seemed to feel the spec should be changed to make it unspecified 
> behavior.
> 
> The behavior of
>     printf '%b\n' '\x61'
> 
> is clearly unspecified already.
> 
> Philip Guenther
> 
> 
> On Sun, Apr 18, 2021 at 7:02 AM Martijn van Duren 
> <openbsd+t...@list.imperialat.at> wrote:
> > On Thu, 2021-04-15 at 19:48 -0600, Todd C. Miller wrote:
> > > On Fri, 16 Apr 2021 03:34:04 +0200, Martijn van Duren wrote:
> > > 
> > > > We currently have NetBSD's behaviour when it comes to to no characters,
> > > > so no need to change there imho, but the 2 character limit seems like
> > > > a good place to stop, especially since there's no way to break out of
> > > > this hungry hungry hippo.
> > > > 
> > > > limiter inspiration taken from octal notation.
> > > > 
> > > > While here, also document \x notation.
> > > 
> > > No objection from me but I'm not sure it needs to make 6.9.
> > > 
> > >  - todd
> > I found a (different) bug in NetBSD's implementation, which got fixed by
> > christos. But he also added a check that at least 1 isxdigit(3) needs to
> > be present. From the commit message:
> > Also add a warning if the conversion fails (like the gnu printf does)
> > 
> > Do we want something similar now that we are the odd ones out, or keep
> > the diff as is? I still think that the current diff is fine, but since
> > the landscape changed I wanted to throw it out there.
> > 
> > martijn@
> > 
[0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
[1] 
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html#tag_05

Reply via email to