qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Alberto Garcia <berto@igalia.com>, qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>
Subject: Re: [PATCH v2] qcow2: Use a GString in report_unsupported_feature()
Date: Wed, 15 Jan 2020 15:23:31 +0100	[thread overview]
Message-ID: <413ac14e-306d-5e57-fa54-10fce9a5a058@redhat.com> (raw)
In-Reply-To: <20200115135626.19442-1-berto@igalia.com>

On 1/15/20 2:56 PM, Alberto Garcia wrote:
> This is a bit more efficient than having to allocate and free memory
> for each item.
> 
> The default size (60) is enough for all the existing incompatible
> features or the "Unknown incompatible feature" message.
> 
> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   block/qcow2.c | 23 +++++++++++------------
>   1 file changed, 11 insertions(+), 12 deletions(-)
> 
> v2: Use g_autoptr and update commit message
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index cef9d72b3a..e29fc07068 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -453,16 +453,15 @@ static void cleanup_unknown_header_ext(BlockDriverState *bs)
>   static void report_unsupported_feature(Error **errp, Qcow2Feature *table,
>                                          uint64_t mask)
>   {
> -    char *features = g_strdup("");
> -    char *old;
> +    g_autoptr(GString) features = g_string_sized_new(60);
>   
>       while (table && table->name[0] != '\0') {
>           if (table->type == QCOW2_FEAT_TYPE_INCOMPATIBLE) {
>               if (mask & (1ULL << table->bit)) {
> -                old = features;
> -                features = g_strdup_printf("%s%s%.46s", old, *old ? ", " : "",
> -                                           table->name);
> -                g_free(old);
> +                if (features->len > 0) {
> +                    g_string_append(features, ", ");
> +                }
> +                g_string_append_printf(features, "%.46s", table->name);
>                   mask &= ~(1ULL << table->bit);
>               }
>           }
> @@ -470,14 +469,14 @@ static void report_unsupported_feature(Error **errp, Qcow2Feature *table,
>       }
>   
>       if (mask) {
> -        old = features;
> -        features = g_strdup_printf("%s%sUnknown incompatible feature: %" PRIx64,
> -                                   old, *old ? ", " : "", mask);
> -        g_free(old);
> +        if (features->len > 0) {
> +            g_string_append(features, ", ");
> +        }
> +        g_string_append_printf(features,
> +                               "Unknown incompatible feature: %" PRIx64, mask);
>       }
>   
> -    error_setg(errp, "Unsupported qcow2 feature(s): %s", features);
> -    g_free(features);
> +    error_setg(errp, "Unsupported qcow2 feature(s): %s", features->str);
>   }
>   
>   /*
> 

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



  reply	other threads:[~2020-01-15 14:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 13:56 [PATCH v2] qcow2: Use a GString in report_unsupported_feature() Alberto Garcia
2020-01-15 14:23 ` Philippe Mathieu-Daudé [this message]
2020-01-16 10:40 ` Stefano Garzarella
2020-01-16 12:19 ` Max Reitz
2020-01-16 12:27   ` Alberto Garcia

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=413ac14e-306d-5e57-fa54-10fce9a5a058@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.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 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).