From: Robert Kessl Date: Thu, 10 Jul 2014 08:16:28 +0000 (+0200) Subject: tableprinter: fix of table_make_instance, incorrect initialization of column order X-Git-Tag: v6.1~3^2~104 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b2013773f4e301b7793b076c56f567d48004103d;p=libucw.git tableprinter: fix of table_make_instance, incorrect initialization of column order --- diff --git a/ucw/table.c b/ucw/table.c index cdd735f9..0fc8b572 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -25,18 +25,8 @@ static struct table *table_make_instance(const struct table_template *tbl_templa struct table *new_inst = xmalloc_zero(sizeof(struct table)); // FIXME: update allocation to the weird schema made by pchar and mj? new_inst->pool = mp_new(4096); - if(tbl_template->column_order) { - new_inst->column_order = mp_alloc_zero(new_inst->pool, sizeof(struct table_col_instance) * tbl_template->cols_to_output); - memcpy(new_inst->column_order, tbl_template->column_order, sizeof(struct table_col_instance) * tbl_template->cols_to_output); - for(uint i = 0; i < new_inst->cols_to_output; i++) { - new_inst->column_order[i].cell_content = NULL; - new_inst->column_order[i].col_def = NULL; - new_inst->column_order[i].output_type = tbl_template->column_order[i].output_type; - } - - new_inst->cols_to_output = tbl_template->cols_to_output; - } + // initialize column definitions int col_count = 0; // count the number of columns in the struct table for(;;) { if(tbl_template->columns[col_count].name == NULL && @@ -55,6 +45,21 @@ static struct table *table_make_instance(const struct table_template *tbl_templa new_inst->columns = mp_alloc_zero(new_inst->pool, sizeof(struct table_column) * new_inst->column_count); memcpy(new_inst->columns, tbl_template->columns, sizeof(struct table_column) * new_inst->column_count); + // initialize column_order + if(tbl_template->column_order) { + new_inst->column_order = mp_alloc_zero(new_inst->pool, sizeof(struct table_col_instance) * tbl_template->cols_to_output); + memcpy(new_inst->column_order, tbl_template->column_order, sizeof(struct table_col_instance) * tbl_template->cols_to_output); + for(uint i = 0; i < new_inst->cols_to_output; i++) { + new_inst->column_order[i].cell_content = NULL; + //new_inst->column_order[i].col_def = NULL; // FIXME: col_def should not be touched, probably ... + int col_idx = new_inst->column_order[i].idx;//col_order[i]; + new_inst->column_order[i].col_def = new_inst->columns + col_idx; + new_inst->column_order[i].output_type = tbl_template->column_order[i].output_type; + } + + new_inst->cols_to_output = tbl_template->cols_to_output; + } + new_inst->col_delimiter = tbl_template->col_delimiter; new_inst->print_header = 1; new_inst->out = 0;