[Qemu-devel] [PATCH 11/22] qcow2: remove useless NULL check

Marc-André Lureau posted 22 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 11/22] qcow2: remove useless NULL check
Posted by Marc-André Lureau 8 years, 5 months ago
g_strdup() already handles the case where the argument is NULL.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 block/qcow2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 96fb8a8f16..9114218030 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2016,8 +2016,8 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
     g_free(s->image_backing_file);
     g_free(s->image_backing_format);
 
-    s->image_backing_file = backing_file ? g_strdup(bs->backing_file) : NULL;
-    s->image_backing_format = backing_fmt ? g_strdup(bs->backing_format) : NULL;
+    s->image_backing_file = g_strdup(bs->backing_file);
+    s->image_backing_format = g_strdup(bs->backing_format);
 
     return qcow2_update_header(bs);
 }
-- 
2.11.0.295.gd7dffce1c.dirty


Re: [Qemu-devel] [PATCH 11/22] qcow2: remove useless NULL check
Posted by Paolo Bonzini 8 years, 5 months ago

On 02/02/2017 15:51, Marc-André Lureau wrote:
> g_strdup() already handles the case where the argument is NULL.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  block/qcow2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 96fb8a8f16..9114218030 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2016,8 +2016,8 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
>      g_free(s->image_backing_file);
>      g_free(s->image_backing_format);
>  
> -    s->image_backing_file = backing_file ? g_strdup(bs->backing_file) : NULL;
> -    s->image_backing_format = backing_fmt ? g_strdup(bs->backing_format) : NULL;
> +    s->image_backing_file = g_strdup(bs->backing_file);
> +    s->image_backing_format = g_strdup(bs->backing_format);
>  
>      return qcow2_update_header(bs);
>  }
> 

Please send this separately with Cc to qemu-trivial.

Paolo