diff options
author | Igor Gnatenko | 2016-01-22 12:54:02 +0100 |
---|---|---|
committer | Igor Gnatenko | 2016-01-22 12:54:02 +0100 |
commit | 0a69e647fcd01c9dbf4a12949a0299af8149dca8 (patch) | |
tree | b1656dbe56ccdd62716b43241f3fd8c893ab9555 /libsmartcols/src/table.c | |
parent | libsmartcols: put new line after title (diff) | |
download | kernel-qcow2-util-linux-0a69e647fcd01c9dbf4a12949a0299af8149dca8.tar.gz kernel-qcow2-util-linux-0a69e647fcd01c9dbf4a12949a0299af8149dca8.tar.xz kernel-qcow2-util-linux-0a69e647fcd01c9dbf4a12949a0299af8149dca8.zip |
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>
Diffstat (limited to 'libsmartcols/src/table.c')
-rw-r--r-- | libsmartcols/src/table.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 57f6ed515..a3f480915 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -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) { char *p = NULL; + char *q = NULL; if (!tb) return -EINVAL; @@ -145,12 +146,7 @@ int scols_table_set_title(struct libscols_table *tb, const char *title, int posi if (!p) return -ENOMEM; } - free(tb->title); - tb->title = p; - tb->title_pos = position; - - p = NULL; if (color) { if (isalpha(*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) return -EINVAL; } - p = strdup(color); - if (!p) + q = strdup(color); + if (!q) 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; } |