libsmartcols: set everything once in scols_table_set_title()
Reported-by: Karel Zak <kzak@redhat.com> Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
parent
2f62d9fe3e
commit
0a69e647fc
|
@ -136,6 +136,7 @@ int scols_table_set_name(struct libscols_table *tb, const char *name)
|
||||||
int scols_table_set_title(struct libscols_table *tb, const char *title, int position, const char *color)
|
int scols_table_set_title(struct libscols_table *tb, const char *title, int position, const char *color)
|
||||||
{
|
{
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
|
char *q = NULL;
|
||||||
|
|
||||||
if (!tb)
|
if (!tb)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -145,12 +146,7 @@ int scols_table_set_title(struct libscols_table *tb, const char *title, int posi
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
free(tb->title);
|
|
||||||
tb->title = p;
|
|
||||||
|
|
||||||
tb->title_pos = position;
|
|
||||||
|
|
||||||
p = NULL;
|
|
||||||
if (color) {
|
if (color) {
|
||||||
if (isalpha(*color)) {
|
if (isalpha(*color)) {
|
||||||
color = color_sequence_from_colorname(color);
|
color = color_sequence_from_colorname(color);
|
||||||
|
@ -158,13 +154,16 @@ int scols_table_set_title(struct libscols_table *tb, const char *title, int posi
|
||||||
if (!color)
|
if (!color)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
p = strdup(color);
|
q = strdup(color);
|
||||||
if (!p)
|
if (!q)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
free(tb->title_color);
|
|
||||||
tb->title_color = p;
|
|
||||||
|
|
||||||
|
free(tb->title);
|
||||||
|
free(tb->title_color);
|
||||||
|
tb->title = p;
|
||||||
|
tb->title_color = q;
|
||||||
|
tb->title_pos = position;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue