[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 5fd800e6: Table: --catrowfile will not free st
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 5fd800e6: Table: --catrowfile will not free string column contents |
Date: |
Mon, 14 Feb 2022 17:06:02 -0500 (EST) |
branch: master
commit 5fd800e6588d9b98d60bad87213f7085e7485e24
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Table: --catrowfile will not free string column contents
Until now, when Table's row concatenation ('--catrowfile') was used with a
column containing strings, it would mistakenly free the contents of the
strings. Therefore when we later wanted to write the string column, Table
would crash with a segmentation fault!
With this commit, after copying the pointers to the strings from the input
tables into the output table, we set the initial points to 'NULL' so they
aren't freed. This fixes the problem.
I also noticed that I had forgot to add Ignacio Ruiz Cejudo to the
'doc/announce-acknowledge.txt' for his help in the previous bug.
This bug was reported by Manuel Sánchez-Benavente.
This fixes bug #62054.
---
NEWS | 3 +++
bin/table/table.c | 23 ++++++++++++++++++++---
doc/announce-acknowledge.txt | 1 +
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index bb788f9f..ad27a5c5 100644
--- a/NEWS
+++ b/NEWS
@@ -197,6 +197,9 @@ See the end of the file for license conditions.
bug #62052: WCS decomposition of CD into PC+CDELT not setting interanal
values; reported by Ignacio Ruiz Cejudo and Raul
Infante-Sainz.
+ bug #62054: Crash in Table's '--catrowfile' when string column is present;
+ reported by Manuel Sánchez-Benavente.
+
diff --git a/bin/table/table.c b/bin/table/table.c
index 6ce68a0f..341b984f 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -852,10 +852,11 @@ table_catrows_findhdu(char *filename, gal_list_str_t
**hdull)
static size_t
table_catrows_prepare(struct tableparams *p)
{
+ char **strarr;
char *hdu=NULL;
int tableformat;
gal_data_t *tmp, *out=NULL;
- size_t nrows=p->table->size;
+ size_t i, nrows=p->table->size;
gal_list_str_t *filell, *hdull;
size_t numcols, numrows, filledrows=p->table->size;
@@ -882,6 +883,14 @@ table_catrows_prepare(struct tableparams *p)
/* Put the full contents of the existing column into the new
column: this will be the first set of rows, */
memcpy(out->array, tmp->array, tmp->size*gal_type_sizeof(tmp->type));
+
+ /* If the column type is a string, we should set the input pointers
+ to NULL to avoid freeing them later. */
+ if(tmp->type==GAL_TYPE_STRING)
+ {
+ strarr=tmp->array;
+ for(i=0;i<tmp->size;++i) strarr[i]=NULL;
+ }
}
gal_list_data_reverse(&out);
@@ -899,10 +908,10 @@ table_catrows_prepare(struct tableparams *p)
static void
table_catrows(struct tableparams *p)
{
- char *hdu=NULL;
+ char *hdu=NULL, **strarr;
gal_data_t *new, *ttmp, *tmp;
gal_list_str_t *filell, *hdull;
- size_t colcount, ncols, ncolstest, filledrows;
+ size_t i, colcount, ncols, ncolstest, filledrows;
/* Make sure enough HDUs are given, and allocate the final output table,
while filling the initiall table rows into it. */
@@ -958,6 +967,14 @@ table_catrows(struct tableparams *p)
memcpy(gal_pointer_increment(ttmp->array, filledrows, ttmp->type),
tmp->array, tmp->size*gal_type_sizeof(tmp->type));
+ /* If the column type is a string, we should set the input
+ pointers to NULL to avoid freeing them later. */
+ if(tmp->type==GAL_TYPE_STRING)
+ {
+ strarr=tmp->array;
+ for(i=0;i<tmp->size;++i) strarr[i]=NULL;
+ }
+
/* Take 'ttmp' to the next column and increment the counter */
ttmp=ttmp->next;
++colcount;
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 549e15bc..7561e69e 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -13,6 +13,7 @@ Raúl Infante-Sainz
Alejandro Lumbreras Calle
Sebastian Luna-Valero
Samane Raji
+Ignacio Ruiz Cejudo
Manuel Sánchez-Benavente
Peter Teuben
Jesús Varela
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 5fd800e6: Table: --catrowfile will not free string column contents,
Mohammad Akhlaghi <=