mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Bruno Haible <bruno@clisp.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] swprintf cannot handle the character 0xff
Date: Mon, 12 Jun 2023 19:54:38 -0400	[thread overview]
Message-ID: <20230612235437.GF4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <2776403.6YUMPnJmAY@nimes>

On Tue, Jun 13, 2023 at 01:09:26AM +0200, Bruno Haible wrote:
> Rich Felker wrote:
> > However, for wide printf:
> > 
> >     c
> >     If no l (ell) qualifier is present, the int argument shall be
> >     converted to a wide character as if by calling the btowc()
> >     function and the resulting wide character shall be written.
> > 
> > There's no specification of what happens if btowc fails here, but
> > passing EOF to btowc is required to fail and return WEOF.
> 
> Possibly. But in the test program that I provided, I pass 255, not
> -1 (= EOF).

Right. I'm not questioning that your bug report is correct, just my
initial proposal for fixing it. Since wide printf is supposed to
perform the conversion as if by btowc, it should presumably handle -1
(as opposed to 255) as an error path.

> It's well-known that the preferred way to convert a 'char' to 'int'
> is not by direct assigment/cast, but by casting to 'unsigned char'.
> That's well-known from [f]getc(), the <ctype.h> functions, etc.
> You don't need to particularly care about programmers who pass
> '\xff' to a function that expects an 'int'.

On targets where plain char is signed, '\xff' has value -1, meaning it
would work for %c with narrow printf but not with wide printf. I
wonder if this should actually be a defect and if wide printf should
be specified as converting the value, converted to (unsigned char), as
if by btowc, rather than the raw value.

Rich

  reply	other threads:[~2023-06-12 23:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 12:30 Bruno Haible
2023-06-12 20:22 ` Rich Felker
2023-06-12 21:01   ` Rich Felker
2023-06-12 21:13     ` Rich Felker
2023-06-12 23:09       ` Bruno Haible
2023-06-12 23:54         ` Rich Felker [this message]
2023-06-13  0:23           ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230612235437.GF4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=bruno@clisp.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).