libsmartcols: use list_add_tail() in more robust way
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
84084dc324
commit
ebc2397ec4
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue