summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2019-02-18 12:33:12 +0100
committerKarel Zak2019-02-18 12:33:12 +0100
commitebc2397ec4ebef700c27297f394a3460a7d0f754 (patch)
tree5656bf372fdc4049a0c662a4fb6b7cfc4924656b /libsmartcols
parentlibblkid: tiny code simplification (diff)
downloadkernel-qcow2-util-linux-ebc2397ec4ebef700c27297f394a3460a7d0f754.tar.gz
kernel-qcow2-util-linux-ebc2397ec4ebef700c27297f394a3460a7d0f754.tar.xz
kernel-qcow2-util-linux-ebc2397ec4ebef700c27297f394a3460a7d0f754.zip
libsmartcols: use list_add_tail() in more robust way
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/grouping.c6
-rw-r--r--libsmartcols/src/table.c6
2 files changed, 12 insertions, 0 deletions
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)