Drop superfluous conditionals around g_strdup()
PATCH 1/1 Drop superfluous conditionals around g_strdup()
--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)
backends/rng-random.c +1 -5
@@ -88,11 +88,7 @@ static char *rng_random_get_filename(Object *obj, Error **errp) {RndRandom *s =RNG_RANDOM (obj); -if (s->filename) { -return g_strdup (s->filename); - } - -return NULL ; +return g_strdup (s->filename); } static void rng_random_set_filename(Object *obj, const char *filename,
hw/tpm/tpm_passthrough.c +1 -3
@@ -400,9 +400,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)const char *value; value =qemu_opt_get (opts,"cancel-path" ); -if (value) { - tb->cancel_path =g_strdup (value); - } + tb->cancel_path =g_strdup (value); value =qemu_opt_get (opts,"path" );if (!value) {
util/uri.c +17 -26
74 lines not on this page · raw message
Signature · 1 line
1.9.3
Quoted 124 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)backends/rng-random.c +1
-5@@ -88,11 +88,7 @@ static char *rng_random_get_filename(Object *obj, Error **errp) {RndRandom *s =RNG_RANDOM (obj); -if (s->filename) { -return g_strdup (s->filename); - } - -return NULL ; +return g_strdup (s->filename); } static void rng_random_set_filename(Object *obj, const char *filename,hw/tpm/tpm_passthrough.c +1
-3@@ -400,9 +400,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)const char *value; value =qemu_opt_get (opts,"cancel-path" ); -if (value) { - tb->cancel_path =g_strdup (value); - } + tb->cancel_path =g_strdup (value); value =qemu_opt_get (opts,"path" );if (!value) {util/uri.c +17
-26@@ -1736,24 +1736,21 @@ uri_resolve(const char *uri, const char *base) { goto done;if ((ref->scheme ==NULL ) && (ref->path ==NULL ) && ((ref->authority ==NULL ) && (ref->server ==NULL ))) { -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme);if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); - res->port = bas->port; + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); + res->port = bas->port; } -if (bas->path !=NULL ) - res->path =g_strdup (bas->path); -if (ref->query !=NULL ) + res->path =g_strdup (bas->path); +if (ref->query !=NULL ) { res->query =g_strdup (ref->query); -else if (bas->query !=NULL ) - res->query =g_strdup (bas->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + }else { + res->query =g_strdup (bas->query); + } + res->fragment =g_strdup (ref->fragment); goto step_7; }@@ -1767,13 +1764,10 @@ uri_resolve(const char *uri, const char *base) { val =uri_to_string (ref); goto done; } -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme); -if (ref->query !=NULL ) - res->query =g_strdup (ref->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + res->query =g_strdup (ref->query); + res->fragment =g_strdup (ref->fragment);/* * 4) If the authority component is defined, then the reference is a @@ -1787,20 +1781,17 @@ uri_resolve(const char *uri, const char *base) { res->authority =g_strdup (ref->authority); else { res->server =g_strdup (ref->server); -if (ref->user !=NULL ) - res->user =g_strdup (ref->user); + res->user =g_strdup (ref->user); res->port = ref->port; } -if (ref->path !=NULL ) - res->path =g_strdup (ref->path); + res->path =g_strdup (ref->path); goto step_7; }if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); res->port = bas->port; }Signature · 1 line
1.9.3
Very confusing tab/whitespace mixture. Code is better, format is worse. I'm not sure it's a win. :)
Fam
Quoted 121 lines · Fam Zheng
Quoted 120 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)backends/rng-random.c +1
-5@@ -88,11 +88,7 @@ static char *rng_random_get_filename(Object *obj, Error **errp) {RndRandom *s =RNG_RANDOM (obj); -if (s->filename) { -return g_strdup (s->filename); - } - -return NULL ; +return g_strdup (s->filename); } static void rng_random_set_filename(Object *obj, const char *filename,hw/tpm/tpm_passthrough.c +1
-3@@ -400,9 +400,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)const char *value; value =qemu_opt_get (opts,"cancel-path" ); -if (value) { - tb->cancel_path =g_strdup (value); - } + tb->cancel_path =g_strdup (value); value =qemu_opt_get (opts,"path" );if (!value) {util/uri.c +17
-26@@ -1736,24 +1736,21 @@ uri_resolve(const char *uri, const char *base) { goto done;if ((ref->scheme ==NULL ) && (ref->path ==NULL ) && ((ref->authority ==NULL ) && (ref->server ==NULL ))) { -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme);if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); - res->port = bas->port; + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); + res->port = bas->port; } -if (bas->path !=NULL ) - res->path =g_strdup (bas->path); -if (ref->query !=NULL ) + res->path =g_strdup (bas->path); +if (ref->query !=NULL ) { res->query =g_strdup (ref->query); -else if (bas->query !=NULL ) - res->query =g_strdup (bas->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + }else { + res->query =g_strdup (bas->query); + } + res->fragment =g_strdup (ref->fragment); goto step_7; }@@ -1767,13 +1764,10 @@ uri_resolve(const char *uri, const char *base) { val =uri_to_string (ref); goto done; } -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme); -if (ref->query !=NULL ) - res->query =g_strdup (ref->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + res->query =g_strdup (ref->query); + res->fragment =g_strdup (ref->fragment);/* * 4) If the authority component is defined, then the reference is a @@ -1787,20 +1781,17 @@ uri_resolve(const char *uri, const char *base) { res->authority =g_strdup (ref->authority); else { res->server =g_strdup (ref->server); -if (ref->user !=NULL ) - res->user =g_strdup (ref->user); + res->user =g_strdup (ref->user); res->port = ref->port; } -if (ref->path !=NULL ) - res->path =g_strdup (ref->path); + res->path =g_strdup (ref->path); goto step_7; }if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); res->port = bas->port; }
Quoted 7 lines
Quoted 4 lines
Signature · 1 line
1.9.3Very confusing tab/whitespace mixture. Code is better, format is worse. I'm not sure it's a win. :)
As per standard operating procedure, I expanded tabs in the lines I touched. No visual difference, except in patches.
What do you want me to do?
1. Don't expand tabs, ignore checkpatch.pl whining
2. Expand tabs in touched lines (current patch)
3. Expand all tabs in uri_resolve() (in a separate patch, of course)
4. Expand all tabs in util/uri.c (in a separate patch, of course)
Fam Zheng
Reviewed-byQuoted 55 lines · Markus Armbruster
Quoted 53 lines · Fam Zheng
Quoted 52 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)backends/rng-random.c +1
-5@@ -88,11 +88,7 @@ static char *rng_random_get_filename(Object *obj, Error **errp) {RndRandom *s =RNG_RANDOM (obj); -if (s->filename) { -return g_strdup (s->filename); - } - -return NULL ; +return g_strdup (s->filename); } static void rng_random_set_filename(Object *obj, const char *filename,hw/tpm/tpm_passthrough.c +1
-3@@ -400,9 +400,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)const char *value; value =qemu_opt_get (opts,"cancel-path" ); -if (value) { - tb->cancel_path =g_strdup (value); - } + tb->cancel_path =g_strdup (value); value =qemu_opt_get (opts,"path" );if (!value) {util/uri.c +1
-2@@ -1736,24 +1736,21 @@ uri_resolve(const char *uri, const char *base) { goto done;if ((ref->scheme ==NULL ) && (ref->path ==NULL ) && ((ref->authority ==NULL ) && (ref->server ==NULL ))) { -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme);if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);
Quoted 8 lines
Quoted 8 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1745
Quoted 8 lines
util/uri.c +3
-4else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); - res->port = bas->port; + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); + res->port = bas->port;
You fixed indentation for res->server and res->port ...
Quoted 7 lines
Quoted 7 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1749
Quoted 7 lines
util/uri.c +2
-3} -if (bas->path !=NULL ) - res->path =g_strdup (bas->path); -if (ref->query !=NULL ) + res->path =g_strdup (bas->path); +if (ref->query !=NULL ) { res->query =g_strdup (ref->query);
... but not for res->query.
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
util/uri.c +9
-10+ }else { + res->query =g_strdup (bas->query); + } + res->fragment =g_strdup (ref->fragment); goto step_7; }@@ -1767,13 +1764,10 @@ uri_resolve(const char *uri, const char *base) { val =uri_to_string (ref); goto done; } -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme); -if (ref->query !=NULL ) - res->query =g_strdup (ref->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + res->query =g_strdup (ref->query); + res->fragment =g_strdup (ref->fragment);/* * 4) If the authority component is defined, then the reference is a @@ -1787,20 +1781,17 @@ uri_resolve(const char *uri, const char *base) { res->authority =g_strdup (ref->authority); else { res->server =g_strdup (ref->server); -if (ref->user !=NULL ) - res->user =g_strdup (ref->user); + res->user =g_strdup (ref->user); res->port = ref->port; } -if (ref->path !=NULL ) - res->path =g_strdup (ref->path); + res->path =g_strdup (ref->path); goto step_7; }if (bas->authority !=NULL )
Quoted 8 lines
Quoted 8 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1795
Quoted 8 lines
util/uri.c +2
-3res->authority =g_strdup (bas->authority); else if (bas->server != NULL) { - res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); res->port = bas->port;
and not for res->port.
Quoted 15 lines
Quoted 9 lines
Quoted 6 lines
util/uri.c +0
-0}Signature · 1 line
1.9.3Very confusing tab/whitespace mixture. Code is better, format is worse. I'm not sure it's a win. :)
As per standard operating procedure, I expanded tabs in the lines I touched. No visual difference, except in patches.
What do you want me to do?
Quoted 8 lines
1. Don't expand tabs, ignore checkpatch.pl whining
2. Expand tabs in touched lines (current patch)
3. Expand all tabs in
uri_resolve()(in a separate patch, of course)4. Expand all tabs in
util/uri.c(in a separate patch, of course)
Well, I never know what to do with legacy tabs, perhaps it's not worth polluting git blame. The code looks good, as a reviewer I'm happy to add my
if maintainers are happy with the indentation.
Fam
Quoted 58 lines · Fam Zheng
Quoted 57 lines · Markus Armbruster
Quoted 55 lines · Fam Zheng
Quoted 54 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)backends/rng-random.c +1
-5@@ -88,11 +88,7 @@ static char *rng_random_get_filename(Object *obj, Error **errp) {RndRandom *s =RNG_RANDOM (obj); -if (s->filename) { -return g_strdup (s->filename); - } - -return NULL ; +return g_strdup (s->filename); } static void rng_random_set_filename(Object *obj, const char *filename,hw/tpm/tpm_passthrough.c +1
-3@@ -400,9 +400,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb)const char *value; value =qemu_opt_get (opts,"cancel-path" ); -if (value) { - tb->cancel_path =g_strdup (value); - } + tb->cancel_path =g_strdup (value); value =qemu_opt_get (opts,"path" );if (!value) {util/uri.c +1
-3@@ -1736,24 +1736,21 @@ uri_resolve(const char *uri, const char *base) { goto done;if ((ref->scheme ==NULL ) && (ref->path ==NULL ) && ((ref->authority ==NULL ) && (ref->server ==NULL ))) { -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme);if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) { - res->server =g_strdup (bas->server);
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1745
Quoted 6 lines
util/uri.c +3
-3-if (bas->user !=NULL ) - res->user =g_strdup (bas->user); - res->port = bas->port; + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); + res->port = bas->port;You fixed indentation for
res->serverandres->port...
... because I touched these lines...
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1749
Quoted 7 lines
util/uri.c +2
-3} -if (bas->path !=NULL ) - res->path =g_strdup (bas->path); -if (ref->query !=NULL ) + res->path =g_strdup (bas->path); +if (ref->query !=NULL ) { res->query =g_strdup (ref->query);... but not for
res->query.
... because I didn't touch this line.
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
util/uri.c +9
-10+ }else { + res->query =g_strdup (bas->query); + } + res->fragment =g_strdup (ref->fragment); goto step_7; }@@ -1767,13 +1764,10 @@ uri_resolve(const char *uri, const char *base) { val =uri_to_string (ref); goto done; } -if (bas->scheme !=NULL ) - res->scheme =g_strdup (bas->scheme); + res->scheme =g_strdup (bas->scheme); -if (ref->query !=NULL ) - res->query =g_strdup (ref->query); -if (ref->fragment !=NULL ) - res->fragment =g_strdup (ref->fragment); + res->query =g_strdup (ref->query); + res->fragment =g_strdup (ref->fragment);/* * 4) If the authority component is defined, then the reference is a @@ -1787,20 +1781,17 @@ uri_resolve(const char *uri, const char *base) { res->authority =g_strdup (ref->authority); else { res->server =g_strdup (ref->server); -if (ref->user !=NULL ) - res->user =g_strdup (ref->user); + res->user =g_strdup (ref->user); res->port = ref->port; } -if (ref->path !=NULL ) - res->path =g_strdup (ref->path); + res->path =g_strdup (ref->path); goto step_7; }if (bas->authority !=NULL ) res->authority =g_strdup (bas->authority);else if (bas->server !=NULL ) {
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
util/uri.c uri_resolve(const char *uri, const char *base) { · line 1795
Quoted 6 lines
util/uri.c +2
-3- res->server =g_strdup (bas->server); -if (bas->user !=NULL ) - res->user =g_strdup (bas->user); + res->server =g_strdup (bas->server); + res->user =g_strdup (bas->user); res->port = bas->port;and not for
res->port.
Likewise.
Quoted 25 lines
Quoted 16 lines
Quoted 10 lines
Quoted 6 lines
util/uri.c +0
-0}Signature · 1 line
1.9.3Very confusing tab/whitespace mixture. Code is better, format is worse. I'm not
sure it's a win. :)As per standard operating procedure, I expanded tabs in the lines I touched. No visual difference, except in patches.
What do you want me to do?
Quoted 8 lines
1. Don't expand tabs, ignore checkpatch.pl whining
2. Expand tabs in touched lines (current patch)
3. Expand all tabs in
uri_resolve()(in a separate patch, of course)4. Expand all tabs in
util/uri.c(in a separate patch, of course)
Quoted 6 lines
Well, I never know what to do with legacy tabs, perhaps it's not worth polluting git blame. The code looks good, as a reviewer I'm happy to add my
Reviewed-by Fam Zheng <[email protected]>if maintainers are happy with the indentation.
In my private opinion, we should either not bother expanding tabs at all, or we should've expanded them wholesale long ago. Not worth rearguing now.
Quoted 5 lines · Markus Armbruster
As per standard operating procedure, I expanded tabs in the lines I touched. No visual difference, except in patches.
What do you want me to do?
Quoted 7 lines
1. Don't expand tabs, ignore checkpatch.pl whining
2. Expand tabs in touched lines (current patch)
3. Expand all tabs in
uri_resolve()(in a separate patch, of course)4. Expand all tabs in
util/uri.c(in a separate patch, of course)
My preferred choice first: 2, 4, 3, 1
That is, I'm fine with how you did it. If you are going to clean up tabs as a separate patch, I'd prefer you do it for the whole file rather than just one function. And I'd rather a tab cleanup than ignoring checkpatch.pl, but not at the expense of favoring a tab cleanup ahead of the current proposed patch.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 6 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- backends/rng-random.c | 6 +----- hw/tpm/tpm_passthrough.c | 4 +--- util/uri.c | 43 +++++++++++++++++-------------------------- 3 files changed, 19 insertions(+), 34 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Michael Tokarev
AppliedApplied to -trivial, thanks!
/mjt