From 3ea8e01a9d05a36ca79e1f87c70b9901de750a7e Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 4 Dec 2018 12:30:14 +0100 Subject: [PATCH] Fix some cppcheck warnings. Despite it is nonsense and cppcheck should understand the code better :-) --- lib/luks2/luks2_json_metadata.c | 3 ++- lib/verity/verity.c | 3 ++- src/cryptsetup_reencrypt.c | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/luks2/luks2_json_metadata.c b/lib/luks2/luks2_json_metadata.c index a9381382..74cd3f67 100644 --- a/lib/luks2/luks2_json_metadata.c +++ b/lib/luks2/luks2_json_metadata.c @@ -1222,7 +1222,8 @@ int LUKS2_config_get_flags(struct crypt_device *cd, struct luks2_hdr *hdr, uint3 for (i = 0; i < (int) json_object_array_length(jobj_flags); i++) { jobj1 = json_object_array_get_idx(jobj_flags, i); - for (j = 0, found = 0; persistent_flags[j].description && !found; j++) + found = 0; + for (j = 0; persistent_flags[j].description && !found; j++) if (!strcmp(persistent_flags[j].description, json_object_get_string(jobj1))) { *flags |= persistent_flags[j].flag; diff --git a/lib/verity/verity.c b/lib/verity/verity.c index ecaa8cb5..8c08baca 100644 --- a/lib/verity/verity.c +++ b/lib/verity/verity.c @@ -226,7 +226,8 @@ int VERITY_UUID_generate(struct crypt_device *cd, char **uuid_string) { uuid_t uuid; - if (!(*uuid_string = malloc(40))) + *uuid_string = malloc(40); + if (!*uuid_string) return -ENOMEM; uuid_generate(uuid); uuid_unparse(uuid, *uuid_string); diff --git a/src/cryptsetup_reencrypt.c b/src/cryptsetup_reencrypt.c index e9d98165..98e05fe2 100644 --- a/src/cryptsetup_reencrypt.c +++ b/src/cryptsetup_reencrypt.c @@ -303,7 +303,11 @@ static int create_empty_header(const char *new_file, const char *old_file, log_dbg("Creating empty file %s of size %lu.", new_file, (unsigned long)size); - if (!size || !(buf = malloc(size))) + if (!size) + return -EINVAL; + + buf = malloc(size); + if (!buf) return -ENOMEM; memset(buf, 0, size);