diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2019-11-14 17:15:18 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2019-11-14 18:06:42 +0100 |
commit | 70fb31b5d6863248b5adfb2581b706cbb158b30e (patch) | |
tree | 076ac21e880e9a137f26804ea6dec73b737c430c | |
parent | 1f4968289c9c0e2a1e850317ef173df11938b7f3 (diff) | |
download | lvm2-70fb31b5d6863248b5adfb2581b706cbb158b30e.tar.gz |
hints: rewrite function
-rw-r--r-- | lib/label/hints.c | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/lib/label/hints.c b/lib/label/hints.c index 6510fcf74..79648b909 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -586,42 +586,29 @@ static void _filter_to_str(struct cmd_context *cmd, int filter_cfg, char **strp) char *str; int pos = 0; int len = 0; - int ret; *strp = NULL; - if (!(cn = find_config_tree_array(cmd, filter_cfg, NULL))) { + if (!(cn = find_config_tree_array(cmd, filter_cfg, NULL))) /* shouldn't happen because default is a|*| */ return; - } - - for (cv = cn->v; cv; cv = cv->next) { - if (cv->type != DM_CFG_STRING) - continue; - len += (strlen(cv->v.str) + 1); - } - len++; - - if (len == 1) { - /* shouldn't happen because default is a|*| */ - return; - } + for (cv = cn->v; cv; cv = cv->next) + if (cv->type == DM_CFG_STRING) + len += strlen(cv->v.str) + 1; - if (!(str = malloc(len))) + if (!len++ || !(str = malloc(len))) return; - memset(str, 0, len); - - for (cv = cn->v; cv; cv = cv->next) { - if (cv->type != DM_CFG_STRING) - continue; - ret = snprintf(str + pos, len - pos, "%s", cv->v.str); + for (cv = cn->v; cv; cv = cv->next) + if (cv->type == DM_CFG_STRING) { + len = strlen(cv->v.str); + memcpy(str + pos, cv->v.str, len); + pos += len; + str[pos++] = 0; + } - if (ret >= len - pos) - break; - pos += ret; - } + str[pos] = 0; *strp = str; } |