Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230526230000.67b24cd6@inria.fr>
Date: Fri, 26 May 2023 23:00:00 +0200
From: Jₑₙₛ Gustedt <jens.gustedt@...ia.fr>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: Re: [C23 printf 3/3] C23: implement the wfN length modifiers
 for printf

Rich,

on Fri, 26 May 2023 16:33:59 -0400 you (Rich Felker <dalias@...c.org>)
wrote:

> On Fri, May 26, 2023 at 09:41:04PM +0200, Jens Gustedt wrote:
> > Musl only has a difference between fixed-width and fastest-width
> > integer types for N == 16. And even here all architectures have made
> > the same choice, namely mapping to 32 bit types.
> > ---
> >  src/stdio/vfprintf.c  | 9 ++++++++-
> >  src/stdio/vfwprintf.c | 9 ++++++++-
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c
> > index 1a516663..9f02a594 100644
> > --- a/src/stdio/vfprintf.c
> > +++ b/src/stdio/vfprintf.c
> > @@ -529,9 +529,16 @@ static int printf_core(FILE *f, const char
> > *fmt, va_list *ap, union arg *nl_arg, ps=st;
> >  			st=states[st]S(*s++);
> >  			if (st == WPRE) {
> > +				// See if "fast" is requested.
> > Difference is only
> > +				// relevant for a fast type of
> > minimum width 16.
> > +				int fast16 = HPRE;
> > +				if (*s == 'f') {
> > +					fast16 = BARE;
> > +					++s;
> > +				}
> >  				switch (getint(&s)) {
> >  				case 8:  st = HHPRE; goto wpre;
> > -				case 16: st = HPRE; goto wpre;
> > +				case 16: st = fast16; goto wpre;
> >  				case 32: st = BARE; goto wpre;
> >  #if UINTPTR_MAX >= UINT64_MAX
> >  				case 64: st = LPRE; goto wpre;
> > diff --git a/src/stdio/vfwprintf.c b/src/stdio/vfwprintf.c
> > index 4320761a..4e9ce63a 100644
> > --- a/src/stdio/vfwprintf.c
> > +++ b/src/stdio/vfwprintf.c
> > @@ -244,9 +244,16 @@ static int wprintf_core(FILE *f, const wchar_t
> > *fmt, va_list *ap, union arg *nl_ ps=st;
> >  			st=states[st]S(*s++);
> >  			if (st == WPRE) {
> > +				// See if "fast" is requested.
> > Difference is only
> > +				// relevant for a fast type of
> > minimum width 16.
> > +				int fast16 = HPRE;
> > +				if (*s == 'f') {
> > +					fast16 = BARE;
> > +					++s;
> > +				}
> >  				switch (getint(&s)) {
> >  				case 8:  st = HHPRE; goto wpre;
> > -				case 16: st = HPRE; goto wpre;
> > +				case 16: st = fast16; goto wpre;
> >  				case 32: st = BARE; goto wpre;
> >  #if UINTPTR_MAX >= UINT64_MAX
> >  				case 64: st = LPRE; goto wpre;
> > -- 
> > 2.34.1  
> 
> It may just work to have w8, w16, wf8, and wf16 all resolve to BARE
> unconditionally, as the default promitions for variadic functions
> force these all to be passed as int. In the current code, for h and hh
> prefixes we cast down and discard any high bits, but unless the caller
> invoked UB by passing an argument with mismatched type, the cast is
> guaranteed not to change the value.

This might be a nice simplification, I'd have to think of this. At a
first glance this sounds a bit user unfriendly to me.

Jₑₙₛ

-- 
:: ICube :::::::::::::::::::::::::::::: deputy director ::
:: Université de Strasbourg :::::::::::::::::::::: ICPS ::
:: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus ::
:: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 ::
:: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Content of type "application/pgp-signature" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.