* [Qemu-devel] [PATCH] curses: fix wchar_t printf warning
@ 2019-04-02 7:30 Gerd Hoffmann
2019-04-02 12:57 ` Eric Blake
2019-04-12 12:37 ` Peter Maydell
0 siblings, 2 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2019-04-02 7:30 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
On some systems wchar_t is "long int", on others just "int".
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));
return 0xFFFD;
}
--
2.18.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] curses: fix wchar_t printf warning
2019-04-02 7:30 [Qemu-devel] [PATCH] curses: fix wchar_t printf warning Gerd Hoffmann
@ 2019-04-02 12:57 ` Eric Blake
2019-04-02 14:54 ` Philippe Mathieu-Daudé
2019-04-12 12:37 ` Peter Maydell
1 sibling, 1 reply; 4+ messages in thread
From: Eric Blake @ 2019-04-02 12:57 UTC (permalink / raw)
To: Gerd Hoffmann, qemu-devel
[-- 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 --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] curses: fix wchar_t printf warning
2019-04-02 12:57 ` Eric Blake
@ 2019-04-02 14:54 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-04-02 14:54 UTC (permalink / raw)
To: Eric Blake, Gerd Hoffmann, qemu-devel
On 4/2/19 2:57 PM, Eric Blake wrote:
> 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>
>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] curses: fix wchar_t printf warning
2019-04-02 7:30 [Qemu-devel] [PATCH] curses: fix wchar_t printf warning Gerd Hoffmann
2019-04-02 12:57 ` Eric Blake
@ 2019-04-12 12:37 ` Peter Maydell
1 sibling, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2019-04-12 12:37 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: QEMU Developers
On Tue, 2 Apr 2019 at 08:34, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On some systems wchar_t is "long int", on others just "int".
> 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));
> return 0xFFFD;
> }
>
Applied to master since we needed an rc4 for other reasons.
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-12 12:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02 7:30 [Qemu-devel] [PATCH] curses: fix wchar_t printf warning Gerd Hoffmann
2019-04-02 12:57 ` Eric Blake
2019-04-02 14:54 ` Philippe Mathieu-Daudé
2019-04-12 12:37 ` Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.