From 64ccbc4b52749d06925078890fc52c78964ee239 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 13 Jun 2024 23:06:09 +0200 Subject: [PATCH] gcc: check cv pointer when needed As 'cv' was already dereferenced, check for NULL with do {} while(); loop. --- lib/format_text/flags.c | 5 ++--- lib/format_text/import_vsn1.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c index 3890a40cc..29d88ddd3 100644 --- a/lib/format_text/flags.c +++ b/lib/format_text/flags.c @@ -192,7 +192,7 @@ int read_flags(uint64_t *status, enum pv_vg_lv_e type, int mask, const struct dm if (cv->type == DM_CFG_EMPTY_ARRAY) goto out; - while (cv) { + do { if (cv->type != DM_CFG_STRING) { log_error("Status value is not a string."); return 0; @@ -228,8 +228,7 @@ int read_flags(uint64_t *status, enum pv_vg_lv_e type, int mask, const struct dm return 0; } - cv = cv->next; - } + } while ((cv = cv->next)); out: *status |= s; diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 0bba8772a..c03ace175 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -159,7 +159,7 @@ static int _read_str_list(struct dm_pool *mem, struct dm_list *list, const struc if (cv->type == DM_CFG_EMPTY_ARRAY) return 1; - while (cv) { + do { if (cv->type != DM_CFG_STRING) { log_error("Found an item that is not a string"); return 0; @@ -168,8 +168,7 @@ static int _read_str_list(struct dm_pool *mem, struct dm_list *list, const struc if (!str_list_add(mem, list, dm_pool_strdup(mem, cv->v.str))) return_0; - cv = cv->next; - } + } while ((cv = cv->next)); return 1; }