All of lore.kernel.org
 help / color / mirror / Atom feed
* master - hints: rewrite function
@ 2019-11-14 17:07 Zdenek Kabelac
  0 siblings, 0 replies; only message in thread
From: Zdenek Kabelac @ 2019-11-14 17:07 UTC (permalink / raw)
  To: lvm-devel

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=70fb31b5d6863248b5adfb2581b706cbb158b30e
Commit:        70fb31b5d6863248b5adfb2581b706cbb158b30e
Parent:        1f4968289c9c0e2a1e850317ef173df11938b7f3
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Thu Nov 14 17:15:18 2019 +0100
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Thu Nov 14 18:06:42 2019 +0100

hints: rewrite function

---
 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 6510fcf..79648b9 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;
 }




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-14 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14 17:07 master - hints: rewrite function Zdenek Kabelac

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.