[lxc-devel] [lxc/master] Fix returning -1 in functions with return type bool

rikardfalkeborn on Github lxc-bot at linuxcontainers.org
Sun May 12 00:04:04 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 422 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190511/238795f3/attachment.bin>
-------------- next part --------------
From 17e68c49cf920fba52e937dcf6e0071035ee7927 Mon Sep 17 00:00:00 2001
From: Rikard Falkeborn <rikard.falkeborn at gmail.com>
Date: Sun, 12 May 2019 01:39:51 +0200
Subject: [PATCH 1/3] criu: Remove unnecessary return after _exit()

Since _exit() will terminate, the return statement is dead code. Also,
returning -1 from a function with bool as return type is confusing.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn at gmail.com>
---
 src/lxc/criu.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 1b74cf8137..86f6f18367 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -1273,7 +1273,6 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
 		if (!cgroup_ops) {
 			ERROR("failed to cgroup_init()");
 			_exit(EXIT_FAILURE);
-			return -1;
 		}
 
 		os.pipefd = criuout[1];

From 4d927e7f424acc3002531b10af190a947f123ca0 Mon Sep 17 00:00:00 2001
From: Rikard Falkeborn <rikard.falkeborn at gmail.com>
Date: Sun, 12 May 2019 01:46:27 +0200
Subject: [PATCH 2/3] lvm: Fix return value if lvm_create_clone fails

Returning -1 in a function with return type bool is the same as
returning true. Change to return false to indicate error properly.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn at gmail.com>
---
 src/lxc/storage/lvm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lxc/storage/lvm.c b/src/lxc/storage/lvm.c
index e30f821609..cc267b9528 100644
--- a/src/lxc/storage/lvm.c
+++ b/src/lxc/storage/lvm.c
@@ -535,13 +535,13 @@ bool lvm_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
 		if (!newsize && blk_getsize(orig, &size) < 0) {
 			ERROR("Failed to detect size of logical volume \"%s\"",
 			      orig->src);
-			return -1;
+			return false;
 		}
 
 		/* detect filesystem */
 		if (detect_fs(orig, fstype, 100) < 0) {
 			INFO("Failed to detect filesystem type for \"%s\"", orig->src);
-			return -1;
+			return false;
 		}
 	} else if (!newsize) {
 			size = DEFAULT_FS_SIZE;
@@ -553,7 +553,7 @@ bool lvm_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
 	ret = do_lvm_create(src, size, thinpool);
 	if (ret < 0) {
 		ERROR("Failed to create lvm storage volume \"%s\"", src);
-		return -1;
+		return false;
 	}
 
 	cmd_args[0] = fstype;
@@ -563,7 +563,7 @@ bool lvm_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
 	if (ret < 0) {
 		ERROR("Failed to create new filesystem \"%s\" for lvm storage "
 		      "volume \"%s\": %s", fstype, src, cmd_output);
-		return -1;
+		return false;
 	}
 
 	data.orig = orig;

From cdcaad486806b9c892fe3c050444e65c593c4c06 Mon Sep 17 00:00:00 2001
From: Rikard Falkeborn <rikard.falkeborn at gmail.com>
Date: Sun, 12 May 2019 01:47:56 +0200
Subject: [PATCH 3/3] zfs: Fix return value on zfs_snapshot error

Returning -1 in a function with return type bool is the same as
returning true. Change to return false to indicate error properly.

Detected with cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn at gmail.com>
---
 src/lxc/storage/zfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/storage/zfs.c b/src/lxc/storage/zfs.c
index b75708f1c1..fc3b32247e 100644
--- a/src/lxc/storage/zfs.c
+++ b/src/lxc/storage/zfs.c
@@ -427,7 +427,7 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
 	if (ret < 0 || ret >= PATH_MAX) {
 		ERROR("Failed to create string");
 		free(snapshot);
-		return -1;
+		return false;
 	}
 
 	cmd_args.dataset = lxc_storage_get_path(new->src, new->type);


More information about the lxc-devel mailing list