Patchwork [5/5] libcacard/vscclient.c: fix use of uninitialized variable

login
register
mail settings
Submitter Alon Levy
Date June 4, 2013, 8:23 p.m.
Message ID <1370377419-31788-5-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/248856/
State New
Headers show

Comments

Alon Levy - June 4, 2013, 8:23 p.m.
Found by Coverity.

Signed-off-by: Alon Levy <alevy@redhat.com>
---
 libcacard/vscclient.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Peter Maydell - June 4, 2013, 9:12 p.m.
On 4 June 2013 21:23, Alon Levy <alevy@redhat.com> wrote:
> Found by Coverity.
>
> Signed-off-by: Alon Levy <alevy@redhat.com>
> ---
>  libcacard/vscclient.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
> index 5180d29..4275c23 100644
> --- a/libcacard/vscclient.c
> +++ b/libcacard/vscclient.c
> @@ -645,7 +645,7 @@ main(
>      GIOChannel *channel_stdin;
>      char *qemu_host;
>      char *qemu_port;
> -    VSCMsgHeader mhHeader;
> +    VSCMsgHeader mhHeader = {0,};

As far as I can see we only use this variable once:

    send_msg(VSC_Init, mhHeader.reader_id, &init, sizeof(init));

so wouldn't it be better just to directly pass a constant
"0" to the send_msg() call? Hiding a single uint32_t in
a struct seems a bit obscure.

thanks
-- PMM

Patch

diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 5180d29..4275c23 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -645,7 +645,7 @@  main(
     GIOChannel *channel_stdin;
     char *qemu_host;
     char *qemu_port;
-    VSCMsgHeader mhHeader;
+    VSCMsgHeader mhHeader = {0,};
 
     VCardEmulOptions *command_line_options = NULL;