Skip to contentSkip to conversation

qcow2: remove useless NULL check

PATCH In review Marc-André Lureau 4 participants 4 messages Feb 8, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: remove useless NULL check

g_strdup() already handles the case where the argument is NULL.

---
 block/qcow2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/qcow2.c +2 -2
index 96fb8a8f16..9114218030 100644
@@ -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);
 }
Signature · 1 line
2.11.0.295.gd7dffce1c.dirty
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marc-André Lureau

g_strdup() already handles the case where the argument is NULL.

---
 block/qcow2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines
block/qcow2.c +2 -2
index 96fb8a8f16..9114218030 100644
@@ -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);
 }
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Marc-André Lureau
Quoted 12 lines · Marc-André Lureau

g_strdup() already handles the case where the argument is NULL.

---
 block/qcow2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/qcow2.c +0 -0
index 96fb8a8f16..9114218030 100644

block/qcow2.c static int qcow2_change_backing_file(BlockDriverState *bs, · line 2020

Quoted 7 lines
block/qcow2.c +2 -2
@@ -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);

bs->backing_file and bs->backing_format are arrays. They will never be NULL.

The ternary operator tests backing_file and backing_fmt which instead are pointers. So this is not an equivalent conversion.

Max

Quoted 4 lines
block/qcow2.c +0 -0
     return qcow2_update_header(bs);
 }
 
#3 lore raw

Hi

----- Original Message -----

Quoted 26 lines · Marc-André Lureau
Quoted 12 lines

g_strdup() already handles the case where the argument is NULL.

---
 block/qcow2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/qcow2.c +0 -0
index 96fb8a8f16..9114218030 100644

block/qcow2.c static int qcow2_change_backing_file(BlockDriverState · line 2023

Quoted 10 lines
block/qcow2.c +2 -2
@@ -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);

bs->backing_file and bs->backing_format are arrays. They will never be NULL.

Quoted 2 lines

The ternary operator tests backing_file and backing_fmt which instead are pointers. So this is not an equivalent conversion.

oops my bad, ignore ;P a bit uncommon code though, could deserve a comment.

Quoted 10 lines

Max

Quoted 4 lines
 
     return qcow2_update_header(bs);

}