From: Eric Blake <eblake@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] curses: fix wchar_t printf warning
Date: Tue, 2 Apr 2019 07:57:47 -0500 [thread overview]
Message-ID: <ccd76d0f-19f4-9a66-8f64-4f9498d95ea1@redhat.com> (raw)
In-Reply-To: <20190402073018.17747-1-kraxel@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]
On 4/2/19 2:30 AM, Gerd Hoffmann wrote:
> On some systems wchar_t is "long int", on others just "int".
And elsewhere, it's 'short'.
> So go cast to "long int" and adjust the printf format accordingly.
>
> Reported-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> ui/curses.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ui/curses.c b/ui/curses.c
> index cc6d6da68463..fb63945188b2 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -453,8 +453,8 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
> swch = sizeof(wch);
>
> if (iconv(conv, &pwch, &swch, &pch, &sch) == (size_t) -1) {
> - fprintf(stderr, "Could not convert 0x%02x from WCHAR_T to UCS-2: %s\n",
> - wch, strerror(errno));
> + fprintf(stderr, "Could not convert 0x%02lx from WCHAR_T to UCS-2: %s\n",
> + (unsigned long)wch, strerror(errno));
Sadly, I think you are right that a cast is necessary; there is no
reserved printf character for printing wchar_t as an integer, and the
width of wchar_t is unspecified (on 32-bit systems where it is 'long
int', it does not promote to 'int').
You could have also stuck with %02x and (int)wch, for less typing, but
it's not worth the respin.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-04-02 12:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 7:30 [Qemu-devel] [PATCH] curses: fix wchar_t printf warning Gerd Hoffmann
2019-04-02 12:57 ` Eric Blake [this message]
2019-04-02 14:54 ` Philippe Mathieu-Daudé
2019-04-12 12:37 ` Peter Maydell
2019-04-12 12:37 ` Peter Maydell
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=ccd76d0f-19f4-9a66-8f64-4f9498d95ea1@redhat.com \
--to=eblake@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.
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).