qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"John Snow" <jsnow@redhat.com>, "Stefan Weil" <sw@weilnetz.de>,
	"Richard W.M. Jones" <rjones@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH 2/7] block/gluster: Use g_autofree for string in qemu_gluster_parse_json()
Date: Wed, 31 Jul 2024 17:04:00 +0200	[thread overview]
Message-ID: <ZqpSYBIIiDW03-lz@redhat.com> (raw)
In-Reply-To: <20240731143617.3391947-3-peter.maydell@linaro.org>

Am 31.07.2024 um 16:36 hat Peter Maydell geschrieben:
> 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>
> ---
>  block/gluster.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/block/gluster.c b/block/gluster.c
> index f8b415f3812..61ded95e660 100644
> --- a/block/gluster.c
> +++ b/block/gluster.c
> @@ -514,7 +514,6 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
>      SocketAddressList **tail;
>      QDict *backing_options = NULL;
>      Error *local_err = NULL;
> -    char *str = NULL;
>      const char *ptr;
>      int i, type, num_servers;
>  
> @@ -547,7 +546,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
>      tail = &gconf->server;
>  
>      for (i = 0; i < num_servers; i++) {
> -        str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i);
> +        g_autofree char *str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i);

This line is too long now.

With this fixed:
Reviewed-by: Kevin Wolf <kwolf@redhat.com>



  reply	other threads:[~2024-07-31 15:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31 14:36 [PATCH 0/7] block: Miscellaneous minor Coverity fixes Peter Maydell
2024-07-31 14:36 ` [PATCH 1/7] block/vdi.c: Avoid potential overflow when calculating size of write Peter Maydell
2024-07-31 14:59   ` Kevin Wolf
2024-07-31 15:05   ` Stefan Weil via
2024-07-31 14:36 ` [PATCH 2/7] block/gluster: Use g_autofree for string in qemu_gluster_parse_json() Peter Maydell
2024-07-31 15:04   ` Kevin Wolf [this message]
2024-07-31 20:54   ` Philippe Mathieu-Daudé
2024-07-31 14:36 ` [PATCH 3/7] hw/block/pflash_cfi01: Don't decrement pfl->counter below 0 Peter Maydell
2024-07-31 15:07   ` Kevin Wolf
2024-08-05 18:20   ` Philippe Mathieu-Daudé
2024-07-31 14:36 ` [PATCH 4/7] hw/ide/atapi: Be explicit that assigning to s->lcyl truncates Peter Maydell
2024-07-31 14:46   ` Markus Armbruster
2024-07-31 14:49     ` Peter Maydell
2024-07-31 14:57   ` Kevin Wolf
2024-07-31 14:36 ` [PATCH 5/7] hw/block/fdc-isa: Assert that isa_fdc_get_drive_max_chs() found something Peter Maydell
2024-07-31 14:50   ` Markus Armbruster
2024-07-31 14:54   ` Kevin Wolf
2024-07-31 20:56   ` Philippe Mathieu-Daudé
2024-07-31 14:36 ` [PATCH 6/7] hw/ide/pci.c: Remove dead code from bmdma_prepare_buf() Peter Maydell
2024-07-31 15:13   ` Kevin Wolf
2024-07-31 21:02     ` Philippe Mathieu-Daudé
2024-07-31 14:36 ` [PATCH 7/7] block/ssh.c: Don't double-check that characters are hex digits Peter Maydell
2024-07-31 15:21   ` Kevin Wolf
2024-07-31 15:26     ` Peter Maydell
2024-08-05 18:21 ` [PATCH 0/7] block: Miscellaneous minor Coverity fixes Philippe Mathieu-Daudé
2024-08-06  8:11 ` Philippe Mathieu-Daudé

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=ZqpSYBIIiDW03-lz@redhat.com \
    --to=kwolf@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    --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).