[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 101de527: Library (txt.h): col. num. correctly
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 101de527: Library (txt.h): col. num. correctly written in +100 col. tables |
Date: |
Tue, 2 Jul 2024 15:37:52 -0400 (EDT) |
branch: master
commit 101de5276544a735d2b07bc5ecf6de78f0963909
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Library (txt.h): col. num. correctly written in +100 col. tables
Until now, when a table to be written in plain-text had more than 100
columns, the first 9 column numbers would be incorrectly written in the
metadata. This happened because the buffer array that kept the column
number was not being initialized from the start.
With this commit, the problem was fixed by initializing the buffer array
that was used to write the column numbers.
This bug was found with the help of Sepideh Eskandarlou.
This fixes bug #65939.
---
NEWS | 4 ++++
lib/txt.c | 11 +++++------
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index 1fe6e8cb..c1e2c509 100644
--- a/NEWS
+++ b/NEWS
@@ -229,6 +229,10 @@ See the end of the file for license conditions.
- bug #65935: Arithmetic crashes with constants like speed of light.
+ - bug #65939: Column numbers in plain-text table metadata with +100
+ columns incorrectly written for the first 9 (single-digit) columns;
+ found with the help of Sepideh Eskandarlou.
+
diff --git a/lib/txt.c b/lib/txt.c
index ae0ec1da..a9d98828 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -1880,7 +1880,7 @@ txt_write_metadata(FILE *fp, gal_data_t *datall, char
**fmts,
{
gal_data_t *data;
size_t i, j, num=0;
- char *tmp, *nstr, *tstr;
+ char *c, *tmp, *nstr, *tstr;
int nlen, twt, nw=0, uw=0, tw=0, bw=0;
/* Get the maximum width for each information field. */
@@ -1911,7 +1911,6 @@ txt_write_metadata(FILE *fp, gal_data_t *datall, char
**fmts,
data=data->next;
}
-
/* When there are more than 9 columns, we don't want to have cases
like '# Column 1 :' (note the space between '1' and ':', this
space won't exist for the 2 digit colum numbers).
@@ -1929,9 +1928,10 @@ txt_write_metadata(FILE *fp, gal_data_t *datall, char
**fmts,
nlen=strlen(nstr);
for(data=datall; data!=NULL; data=data->next)
{
- /* Print the number into the number string, then add the ':'
- immediately after the number. */
- sprintf(nstr, "%zu", i+1);
+ /* Initialize the string to an empty string, print the number into
+ the number string, then add the ':' immediately after the
+ number. */
+ for(c=nstr;*c!='\0';++c) {*c=' ';} sprintf(nstr, "%zu", i+1);
for(j=1;j<nlen;++j)
if(!isdigit(nstr[j])) nstr[j] = isdigit(nstr[j-1]) ? ':' : ' ';
@@ -1957,7 +1957,6 @@ txt_write_metadata(FILE *fp, gal_data_t *datall, char
**fmts,
++i;
}
-
/* Clean up and return. */
free(nstr);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 101de527: Library (txt.h): col. num. correctly written in +100 col. tables,
Mohammad Akhlaghi <=