All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: mrezanin@redhat.com, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, peter.maydell@linaro.org,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Robert Foley" <robert.foley@linaro.org>
Subject: Re: [PATCH 1/2] test-logging: Fix -Werror=maybe-uninitialized warning
Date: Tue, 21 Jan 2020 10:58:32 +0100	[thread overview]
Message-ID: <14ba746f-97c3-1ae3-c836-ad2e3e213756@redhat.com> (raw)
In-Reply-To: <63b0fcedf7dfe799c8210b113e5dccf32414a89d.1579598240.git.mrezanin@redhat.com>

On 21/01/2020 10.28, mrezanin@redhat.com wrote:
> From: Miroslav Rezanina <mrezanin@redhat.com>
> 
> Checking for uninitialized variables raises warning for file path
> variables in test_logfile_write and test_logfile_lock functions.
> 
> To suppress this warning, initialize varibles to NULL. This is safe
> change as result of g_build_filename is stored to them before any usage.
> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> ---
>  tests/test-logging.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/test-logging.c b/tests/test-logging.c
> index 1e646f0..6387e49 100644
> --- a/tests/test-logging.c
> +++ b/tests/test-logging.c
> @@ -114,8 +114,8 @@ static void test_logfile_write(gconstpointer data)
>      QemuLogFile *logfile2;
>      gchar const *dir = data;
>      Error *err = NULL;
> -    g_autofree gchar *file_path;
> -    g_autofree gchar *file_path1;
> +    g_autofree gchar *file_path = NULL;
> +    g_autofree gchar *file_path1 = NULL;
>      FILE *orig_fd;
>  
>      /*
> @@ -157,7 +157,7 @@ static void test_logfile_lock(gconstpointer data)
>      FILE *logfile;
>      gchar const *dir = data;
>      Error *err = NULL;
> -    g_autofree gchar *file_path;
> +    g_autofree gchar *file_path = NULL;
>  
>      file_path = g_build_filename(dir, "qemu_test_logfile_lock0.log", NULL);

Right. The glib documentation clearly states that "the variable must be
initialized", see:

https://developer.gnome.org/glib/stable/glib-Miscellaneous-Macros.html#g-autofree

So this is the right thing to do here!

Reviewed-by: Thomas Huth <thuth@redhat.com>



  reply	other threads:[~2020-01-21  9:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-21  9:28 [PATCH 0/2] Prevent uninitialized warnings mrezanin
2020-01-21  9:28 ` [PATCH 1/2] test-logging: Fix -Werror=maybe-uninitialized warning mrezanin
2020-01-21  9:58   ` Thomas Huth [this message]
2020-01-21 15:03     ` Robert Foley
2020-01-21  9:28 ` [PATCH 2/2] aspeed/i2c: Prevent uninitialized warning mrezanin
2020-01-21 10:02   ` Thomas Huth
2020-01-21 10:44     ` Cédric Le Goater
2020-01-21 10:57       ` Miroslav Rezanina
2020-01-21 11:43       ` Thomas Huth
2020-02-06 10:13   ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14ba746f-97c3-1ae3-c836-ad2e3e213756@redhat.com \
    --to=thuth@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=mrezanin@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=robert.foley@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.