From ebc2397ec4ebef700c27297f394a3460a7d0f754 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 18 Feb 2019 12:33:12 +0100 Subject: libsmartcols: use list_add_tail() in more robust way Signed-off-by: Karel Zak --- libsmartcols/src/grouping.c | 6 ++++++ libsmartcols/src/table.c | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'libsmartcols') diff --git a/libsmartcols/src/grouping.c b/libsmartcols/src/grouping.c index 23dd7fcf0..c5fb2cb9f 100644 --- a/libsmartcols/src/grouping.c +++ b/libsmartcols/src/grouping.c @@ -77,6 +77,7 @@ static void groups_fix_members_order(struct libscols_line *ln) struct libscols_line *child; if (ln->group) { + INIT_LIST_HEAD(&ln->ln_groups); list_add_tail(&ln->ln_groups, &ln->group->gr_members); DBG(GROUP, ul_debugobj(ln->group, "fixing member line=%p [%zu/%zu]", ln, ln->group->nmembers, @@ -477,10 +478,12 @@ void scols_groups_reset_state(struct libscols_table *tb) static void add_member(struct libscols_group *gr, struct libscols_line *ln) { DBG(GROUP, ul_debugobj(gr, "add member")); + ln->group = gr; gr->nmembers++; scols_ref_group(gr); + INIT_LIST_HEAD(&ln->ln_groups); list_add_tail(&ln->ln_groups, &gr->gr_members); scols_ref_line(ln); } @@ -575,6 +578,9 @@ int scols_line_link_group(struct libscols_line *ln, struct libscols_line *member if (!ln || !member || !member->group || ln->parent) return -EINVAL; + if (!list_empty(&ln->ln_children)) + return -EINVAL; + DBG(GROUP, ul_debugobj(member->group, "add child")); list_add_tail(&ln->ln_children, &member->group->gr_children); diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index e4f27a916..944c1e593 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -225,6 +225,9 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl if (!tb || !cl || cl->table) return -EINVAL; + if (!list_empty(&cl->cl_columns)) + return -EINVAL; + if (cl->flags & SCOLS_FL_TREE) tb->ntreecols++; @@ -594,6 +597,9 @@ int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln) if (!tb || !ln) return -EINVAL; + if (!list_empty(&ln->ln_lines)) + return -EINVAL; + if (tb->ncols > ln->ncells) { int rc = scols_line_alloc_cells(ln, tb->ncols); if (rc) -- cgit v1.2.3-55-g7522