[Qemu-devel] [PATCH] char: cast ARRAY_SIZE() as signed to silent warning on empty array

Philippe Mathieu-Daudé posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170530120919.8874-1-f4bug@amsat.org
Test checkpatch passed
Test docker passed
Test s390x passed
chardev/char.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[Qemu-devel] [PATCH] char: cast ARRAY_SIZE() as signed to silent warning on empty array
Posted by Philippe Mathieu-Daudé 6 years, 10 months ago
chardev/char.c: In function 'chardev_name_foreach':
chardev/char.c:546:19: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
     for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
                   ^

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 chardev/char.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char.c b/chardev/char.c
index 4e3808aefc..7aa0210765 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -543,7 +543,7 @@ chardev_name_foreach(void (*fn)(const char *name, void *opaque), void *opaque)
 
     object_class_foreach(chardev_class_foreach, TYPE_CHARDEV, false, &fe);
 
-    for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
+    for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
         fn(chardev_alias_table[i].alias, opaque);
     }
 }
@@ -589,7 +589,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
         return NULL;
     }
 
-    for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
+    for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
         if (g_strcmp0(chardev_alias_table[i].alias, name) == 0) {
             name = chardev_alias_table[i].typename;
             break;
-- 
2.11.0


Re: [Qemu-devel] [PATCH] char: cast ARRAY_SIZE() as signed to silent warning on empty array
Posted by Marc-André Lureau 6 years, 10 months ago

----- Original Message -----
> chardev/char.c: In function 'chardev_name_foreach':
> chardev/char.c:546:19: error: comparison of unsigned expression < 0 is always
> false [-Werror=type-limits]
>      for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
>                    ^
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  chardev/char.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/chardev/char.c b/chardev/char.c
> index 4e3808aefc..7aa0210765 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -543,7 +543,7 @@ chardev_name_foreach(void (*fn)(const char *name, void
> *opaque), void *opaque)
>  
>      object_class_foreach(chardev_class_foreach, TYPE_CHARDEV, false, &fe);
>  
> -    for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
> +    for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
>          fn(chardev_alias_table[i].alias, opaque);
>      }
>  }
> @@ -589,7 +589,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts,
>          return NULL;
>      }
>  
> -    for (i = 0; i < ARRAY_SIZE(chardev_alias_table); i++) {
> +    for (i = 0; i < (int)ARRAY_SIZE(chardev_alias_table); i++) {
>          if (g_strcmp0(chardev_alias_table[i].alias, name) == 0) {
>              name = chardev_alias_table[i].typename;
>              break;
> --
> 2.11.0
> 
>