[Qemu-devel] [PATCHv2] curses ui: always initialize all curses_line fields

Samuel Thibault posted 1 patch 5 years, 1 month ago
Test asan passed
Test docker-mingw@fedora passed
Test checkpatch passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190315130932.26094-1-samuel.thibault@ens-lyon.org
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
ui/curses.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[Qemu-devel] [PATCHv2] curses ui: always initialize all curses_line fields
Posted by Samuel Thibault 5 years, 1 month ago
cchar_t can contain not only attr and chars fields, but also ext_color.
Initialize the whole structure to zero instead of enumerating fields.

Spotted by Coverity: CID 1399711

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 ui/curses.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index d29098db9f..cc6d6da684 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -75,9 +75,9 @@ static void curses_update(DisplayChangeListener *dcl,
             if (vga_to_curses[ch].chars[0]) {
                 curses_line[x] = vga_to_curses[ch];
             } else {
-                curses_line[x].chars[0] = ch;
-                curses_line[x].chars[1] = 0;
-                curses_line[x].attr = 0;
+                curses_line[x] = (cchar_t) {
+                    .chars[0] = ch,
+                };
             }
             curses_line[x].attr |= at;
         }
-- 
2.20.1


Re: [Qemu-devel] [PATCHv2] curses ui: always initialize all curses_line fields
Posted by Gerd Hoffmann 5 years, 1 month ago
On Fri, Mar 15, 2019 at 02:09:32PM +0100, Samuel Thibault wrote:
> cchar_t can contain not only attr and chars fields, but also ext_color.
> Initialize the whole structure to zero instead of enumerating fields.
> 
> Spotted by Coverity: CID 1399711
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Added to UI patch queue.

thanks,
  Gerd


Re: [Qemu-devel] [PATCHv2] curses ui: always initialize all curses_line fields
Posted by Philippe Mathieu-Daudé 5 years, 1 month ago
On 3/15/19 2:09 PM, Samuel Thibault wrote:
> cchar_t can contain not only attr and chars fields, but also ext_color.
> Initialize the whole structure to zero instead of enumerating fields.
> 
> Spotted by Coverity: CID 1399711
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  ui/curses.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/ui/curses.c b/ui/curses.c
> index d29098db9f..cc6d6da684 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -75,9 +75,9 @@ static void curses_update(DisplayChangeListener *dcl,
>              if (vga_to_curses[ch].chars[0]) {
>                  curses_line[x] = vga_to_curses[ch];
>              } else {
> -                curses_line[x].chars[0] = ch;
> -                curses_line[x].chars[1] = 0;
> -                curses_line[x].attr = 0;
> +                curses_line[x] = (cchar_t) {
> +                    .chars[0] = ch,
> +                };
>              }
>              curses_line[x].attr |= at;
>          }
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Re: [Qemu-devel] [PATCHv2] curses ui: always initialize all curses_line fields
Posted by Peter Maydell 5 years, 1 month ago
On Fri, 15 Mar 2019 at 13:09, Samuel Thibault
<samuel.thibault@ens-lyon.org> wrote:
>
> cchar_t can contain not only attr and chars fields, but also ext_color.
> Initialize the whole structure to zero instead of enumerating fields.
>
> Spotted by Coverity: CID 1399711
>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
>  ui/curses.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/ui/curses.c b/ui/curses.c
> index d29098db9f..cc6d6da684 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -75,9 +75,9 @@ static void curses_update(DisplayChangeListener *dcl,
>              if (vga_to_curses[ch].chars[0]) {
>                  curses_line[x] = vga_to_curses[ch];
>              } else {
> -                curses_line[x].chars[0] = ch;
> -                curses_line[x].chars[1] = 0;
> -                curses_line[x].attr = 0;
> +                curses_line[x] = (cchar_t) {
> +                    .chars[0] = ch,
> +                };
>              }
>              curses_line[x].attr |= at;
>          }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM