gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 482df67: Table: an empty input table will not


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 482df67: Table: an empty input table will not cause a crash with --range
Date: Thu, 13 May 2021 22:52:55 -0400 (EDT)

branch: master
commit 482df678ad297bd8ffe5dcb92b2a60dc963dd153
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Table: an empty input table will not cause a crash with --range
    
    Until now, when Table was called with an empty input and the '--range'
    option, it would crash with a Segmentation fault. This happened because we
    were implicitly always assuming that the input table is full when '--range'
    has been called (since it is the first row-limiter!).
    
    With this commit, a check has been added at the start of the
    'table_select_by_value' function so when the input is empty, it just
    ignores the function over all.
    
    This bug was reported by Sepideh Eskandarloo.
---
 NEWS              | 1 +
 bin/table/table.c | 4 ++++
 lib/data.c        | 7 ++++---
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index c298dfd..cd76386 100644
--- a/NEWS
+++ b/NEWS
@@ -251,6 +251,7 @@ See the end of the file for license conditions.
   bug #60368: CosmicCalculator fails --setdirconf when redshift isn't given
   bug #60483: No warning when file given to '--config' doesn't exist
   bug #60484: Match crashes when called with --coord and --ccol2 (together)
+  bug #60603: Table crashes with an empty input and --range
 
 
 
diff --git a/bin/table/table.c b/bin/table/table.c
index 4f3e805..0f49814 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -398,6 +398,10 @@ table_select_by_value(struct tableparams *p)
   int inplace=GAL_ARITHMETIC_FLAG_INPLACE;
   gal_data_t *mask, *blmask, *addmask=NULL;
 
+  /* It may happen that the input table is empty! In such cases, just
+     return and don't bother with this step. */
+  if(p->table->dsize==NULL) return;
+
   /* Allocate datasets for the necessary numbers and write them in. */
   mask=gal_data_alloc(NULL, GAL_TYPE_UINT8, 1, p->table->dsize, NULL, 1,
                       p->cp.minmapsize, p->cp.quietmmap, NULL, NULL, NULL);
diff --git a/lib/data.c b/lib/data.c
index f8eb11b..4328d30 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -141,9 +141,10 @@ gal_data_initialize(gal_data_t *data, void *array, uint8_t 
type,
 
 
   /* Allocate space for the dsize array, only if the data are to have any
-     dimensions. Note that in our convention, a number has a 'ndim=1' and
-     'dsize[0]=1', A 1D array also has 'ndim=1', but 'dsize[0]>1'. */
-  if(ndim)
+     dimensions or size along the dimensions. Note that in our convention,
+     a number has a 'ndim=1' and 'dsize[0]=1', A 1D array also has
+     'ndim=1', but 'dsize[0]>1'. */
+  if(ndim && dsize)
     {
       /* Allocate dsize. */
       errno=0;



reply via email to

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