qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Hanna Reitz <hreitz@redhat.com>, Stefan Weil <sw@weilnetz.de>
Subject: Re: [PATCH v2 1/4] block/gluster: Use g_autofree for string in qemu_gluster_parse_json()
Date: Tue, 8 Oct 2024 11:44:34 -0700	[thread overview]
Message-ID: <307638d5-395f-4193-b36e-fa38299f2607@linaro.org> (raw)
In-Reply-To: <20241008164708.2966400-2-peter.maydell@linaro.org>

On 10/8/24 09:47, Peter Maydell wrote:
> In the loop in qemu_gluster_parse_json() we do:
> 
>      char *str = NULL;
>      for(...) {
>          str = g_strdup_printf(...);
>          ...
>          if (various errors) {
>              goto out;
>          }
>          ...
>          g_free(str);
>          str = NULL;
>      }
>      return 0;
> out:
>      various cleanups;
>      g_free(str);
>      ...
>      return -errno;
> 
> Coverity correctly complains that the assignment "str = NULL" at the
> end of the loop is unnecessary, because we will either go back to the
> top of the loop and overwrite it, or else we will exit the loop and
> then exit the function without ever reading str again. The assignment
> is there as defensive coding to ensure that str is only non-NULL if
> it's a live allocation, so this is intentional.
> 
> We can make Coverity happier and simplify the code here by using
> g_autofree, since we never need 'str' outside the loop.
> 
> Resolves: Coverity CID 1527385
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> Reviewed-by: Kevin Wolf<kwolf@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> v1->v2: wrap overlong line
> ---
>   block/gluster.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


  reply	other threads:[~2024-10-08 18:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 16:47 [PATCH v2 0/4] block: Miscellaneous minor Coverity fixes Peter Maydell
2024-10-08 16:47 ` [PATCH v2 1/4] block/gluster: Use g_autofree for string in qemu_gluster_parse_json() Peter Maydell
2024-10-08 18:44   ` Richard Henderson [this message]
2024-10-08 16:47 ` [PATCH v2 2/4] block/ssh.c: Don't double-check that characters are hex digits Peter Maydell
2024-10-08 18:46   ` Richard Henderson
2024-10-08 16:47 ` [PATCH v2 3/4] tests/qemu-iotests/211.out: Update to expect MapEntry 'compressed' field Peter Maydell
2024-10-08 16:47 ` [PATCH v2 4/4] block/vdi.c: Make SECTOR_SIZE constant 64-bits Peter Maydell
2024-10-18 13:40 ` [PATCH v2 0/4] block: Miscellaneous minor Coverity fixes Kevin Wolf

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=307638d5-395f-4193-b36e-fa38299f2607@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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 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).