gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 6b0608b1 1/2: Library (txt.c): an empty input


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 6b0608b1 1/2: Library (txt.c): an empty input is given a dsize value of 0
Date: Wed, 4 Jun 2025 16:12:58 -0400 (EDT)

branch: master
commit 6b0608b119db18d3893cb25b3b4ce64b90a76e2a
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (txt.c): an empty input is given a dsize value of 0
    
    Until now, when an empty text file was read by Gnuastro's plain-text
    library, it would free the internal 'dsize' array (to keep the length of
    the dataset along different dimensions). However, this caused a
    segmentation fault in later steps (which by default assume that 'dsize' is
    allocated, but has a value of 0).
    
    In parallel, I noticed that the description of the '--append' option of
    Arithmetic, actually had the description of the same option in the Crop
    program!
    
    Wit this commit, this has been fixed by not freeing the array in
    'lib/txt.c' in such cases, but instead writing a value of zero inside of
    it. The description of Arithmetic's '--append' option has also been
    corrected.
    
    The plain-text table reading bug was reported by Sepideh Eskandarlou.
    
    This fixes bug #67190.
---
 NEWS                  | 3 +++
 bin/arithmetic/args.h | 2 +-
 lib/txt.c             | 5 ++---
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 4f6fdc23..6704f50d 100644
--- a/NEWS
+++ b/NEWS
@@ -221,6 +221,9 @@ See the end of the file for license conditions.
   - #67128: Maskfilled operators wrong output with zero scatter (can happen
     in integer images, for example in the creation of master dark frames).
 
+  - bug #67190: Sorting an empty plain-text table gives segmentation
+    fault. Reported by Sepideh Eskandarlou.
+
 
 
 
diff --git a/bin/arithmetic/args.h b/bin/arithmetic/args.h
index 8a7889c7..708acdd1 100644
--- a/bin/arithmetic/args.h
+++ b/bin/arithmetic/args.h
@@ -185,7 +185,7 @@ struct argp_option program_options[] =
       UI_KEY_APPEND,
       0,
       0,
-      "If output exists, append crop to existing HDUs.",
+      "If output file exists, append to existing HDUs.",
       GAL_OPTIONS_GROUP_OUTPUT,
       &p->append,
       GAL_OPTIONS_NO_ARG_TYPE,
diff --git a/lib/txt.c b/lib/txt.c
index 3221ecc5..75b5e0ec 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -1255,10 +1255,9 @@ txt_read_prepare_table(gal_data_t *info, size_t *indsize,
          allocated spaces and correct the size. */
       if(indsize[0]==0)
         {
-          out->size=0;
+          out->dsize[0]=out->size=0;
           free(out->array);
-          free(out->dsize);
-          out->dsize=out->array=NULL;
+          out->array=NULL;
         }
 
       /* Find the input token (of each line) that each input column starts



reply via email to

[Prev in Thread] Current Thread [Next in Thread]