summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2019-05-02 15:51:29 +0200
committerKarel Zak2019-05-02 15:51:29 +0200
commit883246a104ee3872fd7fb4b3baaa56209a20d6d2 (patch)
treef2834f7582ca80b12307d96048e4bd2078c3c240 /libsmartcols
parentlibsmartcols: (groups) remove hardcoded const numbers (diff)
downloadkernel-qcow2-util-linux-883246a104ee3872fd7fb4b3baaa56209a20d6d2.tar.gz
kernel-qcow2-util-linux-883246a104ee3872fd7fb4b3baaa56209a20d6d2.tar.xz
kernel-qcow2-util-linux-883246a104ee3872fd7fb4b3baaa56209a20d6d2.zip
libsmartcols: fix groups reset, add debugs
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/calculate.c2
-rw-r--r--libsmartcols/src/grouping.c37
-rw-r--r--libsmartcols/src/print.c2
3 files changed, 29 insertions, 12 deletions
diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c
index a1224adee..60b6a8315 100644
--- a/libsmartcols/src/calculate.c
+++ b/libsmartcols/src/calculate.c
@@ -398,7 +398,7 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf)
}
}
done:
- DBG(TAB, ul_debugobj(tb, " final width: %zu (rc=%d)", width, rc));
+ DBG(TAB, ul_debugobj(tb, "-----final width: %zu (rc=%d)-----", width, rc));
ON_DBG(TAB, dbg_columns(tb));
return rc;
diff --git a/libsmartcols/src/grouping.c b/libsmartcols/src/grouping.c
index d01a73330..fc4828c9c 100644
--- a/libsmartcols/src/grouping.c
+++ b/libsmartcols/src/grouping.c
@@ -246,6 +246,9 @@ static struct libscols_group **grpset_locate_freespace(struct libscols_table *tb
if (!tb->grpset_size)
prepend = 0;
+ DBG(TAB, ul_debugobj(tb, "orig grpset:"));
+ grpset_debug(tb, NULL);
+
if (prepend) {
for (i = tb->grpset_size - 1; ; i--) {
if (tb->grpset[i] == NULL) {
@@ -295,8 +298,9 @@ static struct libscols_group **grpset_locate_freespace(struct libscols_table *tb
memset(first, 0, wanted * sizeof(struct libscols_group *));
tb->grpset_size += wanted;
- grpset_debug(tb, NULL);
done:
+ DBG(TAB, ul_debugobj(tb, "new grpset:"));
+ grpset_debug(tb, NULL);
return first;
}
@@ -327,11 +331,11 @@ static int grpset_update(struct libscols_table *tb, struct libscols_line *ln, st
group_state_to_string(state)));
if (state == SCOLS_GSTATE_FIRST_MEMBER && gr->state != SCOLS_GSTATE_NONE) {
- DBG(LINE, ul_debugobj(ln, "wrong group initialization"));
+ DBG(LINE, ul_debugobj(ln, "wrong group initialization (%s)", group_state_to_string(gr->state)));
abort();
}
if (state != SCOLS_GSTATE_NONE && gr->state == SCOLS_GSTATE_LAST_CHILD) {
- DBG(LINE, ul_debugobj(ln, "wrong group termination"));
+ DBG(LINE, ul_debugobj(ln, "wrong group termination (%s)", group_state_to_string(gr->state)));
abort();
}
if (gr->state == SCOLS_GSTATE_LAST_MEMBER &&
@@ -443,7 +447,7 @@ int scols_groups_calculate_grpset(struct libscols_table *tb)
struct libscols_line *ln;
int rc = 0;
- DBG(TAB, ul_debugobj(tb, "grpset calculate [top-level]"));
+ DBG(TAB, ul_debugobj(tb, "grpset calculate [top-level] ->"));
scols_groups_reset_state(tb);
@@ -457,6 +461,7 @@ int scols_groups_calculate_grpset(struct libscols_table *tb)
}
scols_groups_reset_state(tb);
+ DBG(TAB, ul_debugobj(tb, "<- done grpset calculate [top-level]"));
return rc;
}
@@ -468,16 +473,20 @@ void scols_groups_reset_state(struct libscols_table *tb)
DBG(TAB, ul_debugobj(tb, "reset groups states"));
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
- while (scols_table_next_group(tb, &itr, &gr) == 0)
+ while (scols_table_next_group(tb, &itr, &gr) == 0) {
+ DBG(GROUP, ul_debugobj(gr, " reset to NONE"));
gr->state = SCOLS_GSTATE_NONE;
+ }
- if (tb->grpset)
- memset(tb->grpset, 0, tb->grpset_size);
+ if (tb->grpset) {
+ DBG(TAB, ul_debugobj(tb, " zeroize grpset"));
+ memset(tb->grpset, 0, tb->grpset_size * sizeof(struct libscols_group *));
+ }
}
static void add_member(struct libscols_group *gr, struct libscols_line *ln)
{
- DBG(GROUP, ul_debugobj(gr, "add member"));
+ DBG(GROUP, ul_debugobj(gr, "add member %p", ln));
ln->group = gr;
gr->nmembers++;
@@ -519,13 +528,19 @@ int scols_table_group_lines( struct libscols_table *tb,
{
struct libscols_group *gr = NULL;
- if (!tb || (!ln && !member))
+ if (!tb || (!ln && !member)) {
+ DBG(GROUP, ul_debugobj(gr, "failed group lines (no table, line or member)"));
return -EINVAL;
+ }
if (ln && member) {
- if (ln->group && !member->group)
+ if (ln->group && !member->group) {
+ DBG(GROUP, ul_debugobj(gr, "failed group lines (new group, line member of another)"));
return -EINVAL;
- if (ln->group && member->group && ln->group != member->group)
+ }
+ if (ln->group && member->group && ln->group != member->group) {
+ DBG(GROUP, ul_debugobj(gr, "failed group lines (groups mismatch bwteen member and line"));
return -EINVAL;
+ }
}
gr = member->group;
diff --git a/libsmartcols/src/print.c b/libsmartcols/src/print.c
index ec2224f36..5f1fc77e2 100644
--- a/libsmartcols/src/print.c
+++ b/libsmartcols/src/print.c
@@ -893,6 +893,8 @@ int __scols_print_tree(struct libscols_table *tb, struct libscols_buffer *buf)
DBG(TAB, ul_debugobj(tb, "----printing-tree-----"));
+ if (has_groups(tb))
+ scols_groups_reset_state(tb);
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (scols_table_next_line(tb, &itr, &ln) == 0) {