qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ui/curses: Fix build with -m32
@ 2019-05-27 14:25 Max Reitz
  2019-05-27 14:32 ` Samuel Thibault
  2019-05-29  6:41 ` Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Max Reitz @ 2019-05-27 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Max Reitz

wchar_t may resolve to be an unsigned long on 32-bit architectures.
Using the %x conversion specifier will then give a compiler warning:

ui/curses.c: In function ‘get_ucs’:
ui/curses.c:492:49: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘wchar_t’ {aka ‘long int’} [-Werror=format=]
  492 |         fprintf(stderr, "Could not convert 0x%04x "
      |                                              ~~~^
      |                                                 |
      |                                                 unsigned int
      |                                              %04lx
  493 |                         "from wchar_t to a multibyte character: %s\n",
  494 |                         wch, strerror(errno));
      |                         ~~~
      |                         |
      |                         wchar_t {aka long int}
ui/curses.c:504:49: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘wchar_t’ {aka ‘long int’} [-Werror=format=]
  504 |         fprintf(stderr, "Could not convert 0x%04x "
      |                                              ~~~^
      |                                                 |
      |                                                 unsigned int
      |                                              %04lx
  505 |                         "from a multibyte character to UCS-2 : %s\n",
  506 |                         wch, strerror(errno));
      |                         ~~~
      |                         |
      |                         wchar_t {aka long int}

Fix this by casting the wchar_t value to an unsigned long and using %lx
as the conversion specifier.

Fixes: b7b664a4fe9a955338f2e11a0f7433b29c8cbad0
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 ui/curses.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index 1f3fcabb00..e9319eb8ae 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -489,9 +489,9 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
     memset(&ps, 0, sizeof(ps));
     ret = wcrtomb(mbch, wch, &ps);
     if (ret == -1) {
-        fprintf(stderr, "Could not convert 0x%04x "
+        fprintf(stderr, "Could not convert 0x%04lx "
                         "from wchar_t to a multibyte character: %s\n",
-                        wch, strerror(errno));
+                        (unsigned long)wch, strerror(errno));
         return 0xFFFD;
     }
 
@@ -501,9 +501,9 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
     such = sizeof(uch);
 
     if (iconv(conv, &pmbch, &smbch, &puch, &such) == (size_t) -1) {
-        fprintf(stderr, "Could not convert 0x%04x "
+        fprintf(stderr, "Could not convert 0x%04lx "
                         "from a multibyte character to UCS-2 : %s\n",
-                        wch, strerror(errno));
+                        (unsigned long)wch, strerror(errno));
         return 0xFFFD;
     }
 
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/curses: Fix build with -m32
  2019-05-27 14:25 [Qemu-devel] [PATCH] ui/curses: Fix build with -m32 Max Reitz
@ 2019-05-27 14:32 ` Samuel Thibault
  2019-05-29  6:41 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Thibault @ 2019-05-27 14:32 UTC (permalink / raw)
  To: Max Reitz; +Cc: qemu-devel, Gerd Hoffmann

Max Reitz, le lun. 27 mai 2019 16:25:40 +0200, a ecrit:
> wchar_t may resolve to be an unsigned long on 32-bit architectures.
> Using the %x conversion specifier will then give a compiler warning:
> 
> ui/curses.c: In function ‘get_ucs’:
> ui/curses.c:492:49: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘wchar_t’ {aka ‘long int’} [-Werror=format=]
>   492 |         fprintf(stderr, "Could not convert 0x%04x "
>       |                                              ~~~^
>       |                                                 |
>       |                                                 unsigned int
>       |                                              %04lx
>   493 |                         "from wchar_t to a multibyte character: %s\n",
>   494 |                         wch, strerror(errno));
>       |                         ~~~
>       |                         |
>       |                         wchar_t {aka long int}
> ui/curses.c:504:49: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘wchar_t’ {aka ‘long int’} [-Werror=format=]
>   504 |         fprintf(stderr, "Could not convert 0x%04x "
>       |                                              ~~~^
>       |                                                 |
>       |                                                 unsigned int
>       |                                              %04lx
>   505 |                         "from a multibyte character to UCS-2 : %s\n",
>   506 |                         wch, strerror(errno));
>       |                         ~~~
>       |                         |
>       |                         wchar_t {aka long int}
> 
> Fix this by casting the wchar_t value to an unsigned long and using %lx
> as the conversion specifier.
> 
> Fixes: b7b664a4fe9a955338f2e11a0f7433b29c8cbad0
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  ui/curses.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/ui/curses.c b/ui/curses.c
> index 1f3fcabb00..e9319eb8ae 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -489,9 +489,9 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
>      memset(&ps, 0, sizeof(ps));
>      ret = wcrtomb(mbch, wch, &ps);
>      if (ret == -1) {
> -        fprintf(stderr, "Could not convert 0x%04x "
> +        fprintf(stderr, "Could not convert 0x%04lx "
>                          "from wchar_t to a multibyte character: %s\n",
> -                        wch, strerror(errno));
> +                        (unsigned long)wch, strerror(errno));
>          return 0xFFFD;
>      }
>  
> @@ -501,9 +501,9 @@ static uint16_t get_ucs(wchar_t wch, iconv_t conv)
>      such = sizeof(uch);
>  
>      if (iconv(conv, &pmbch, &smbch, &puch, &such) == (size_t) -1) {
> -        fprintf(stderr, "Could not convert 0x%04x "
> +        fprintf(stderr, "Could not convert 0x%04lx "
>                          "from a multibyte character to UCS-2 : %s\n",
> -                        wch, strerror(errno));
> +                        (unsigned long)wch, strerror(errno));
>          return 0xFFFD;
>      }
>  
> -- 
> 2.21.0
> 
> 

-- 
Samuel
/*
 * [...] Note that 120 sec is defined in the protocol as the maximum
 * possible RTT.  I guess we'll have to use something other than TCP
 * to talk to the University of Mars.
 * PAWS allows us longer timeouts and large windows, so once implemented
 * ftp to mars will work nicely.
 */
(from /usr/src/linux/net/inet/tcp.c, concerning RTT [retransmission timeout])


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] ui/curses: Fix build with -m32
  2019-05-27 14:25 [Qemu-devel] [PATCH] ui/curses: Fix build with -m32 Max Reitz
  2019-05-27 14:32 ` Samuel Thibault
@ 2019-05-29  6:41 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2019-05-29  6:41 UTC (permalink / raw)
  To: Max Reitz; +Cc: qemu-devel

On Mon, May 27, 2019 at 04:25:40PM +0200, Max Reitz wrote:
> wchar_t may resolve to be an unsigned long on 32-bit architectures.
> Using the %x conversion specifier will then give a compiler warning:

Added to ui queue.

thanks,
  Gerd



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-29  6:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-27 14:25 [Qemu-devel] [PATCH] ui/curses: Fix build with -m32 Max Reitz
2019-05-27 14:32 ` Samuel Thibault
2019-05-29  6:41 ` Gerd Hoffmann

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).