gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master d289ef29: Library (blank.h): gal_blank_flag re


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master d289ef29: Library (blank.h): gal_blank_flag returns uint8 output on empty input
Date: Tue, 22 Nov 2022 06:58:18 -0500 (EST)

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

    Library (blank.h): gal_blank_flag returns uint8 output on empty input
    
    Until now, when the input to 'gal_blank_flag' was an empty dataset, the it
    would simply return the input! However, this would ignore the fact that the
    input can have any data type, and doesn't have to be an unsigned 8-bit
    integer (which is the expected format of a flag).
    
    As a result, when the Table program was called with '--noblank' or
    '--noblankend' on an empty input table, the Table program would abort,
    saying that the type of the flag is not correct! Also, when '--noblank' was
    used on an empty table, Table would give a segmentation fault!
    
    With this commit, when the input to 'gal_blank_flag' is empty, a new empty
    dataset is allocated with the unsigned 8-bit integer type and returned as
    flag. This fixed the problem with the wrong type of flag. For the
    segmentation fault, I noticed that we are only checking for 'dsize' being
    NULL (to identify if the table is empty!), but other scenarios may also
    happen. So we now also check the size and the presense of an array.
    
    This bug was reported by Elham Saremi.
    
    This fixes bug #63399.
---
 NEWS              |  2 ++
 bin/table/table.c |  3 ++-
 lib/blank.c       | 19 +++++++++++++++----
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 58bc7f39..430980f3 100644
--- a/NEWS
+++ b/NEWS
@@ -105,6 +105,8 @@ See the end of the file for license conditions.
   bug #63345: WCS coordinate change not accounting for new equinox (only
               relevant for equatorial outputs). Reported by Alejandro
               Serrano Borlaff.
+  bug #63399: Table's '--noblank' or '--noblankend' crashing when input
+              has no rows. Reported by Elham Saremi.
 
 
 
diff --git a/bin/table/table.c b/bin/table/table.c
index 76be7f69..684a7520 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -400,7 +400,8 @@ table_select_by_value(struct tableparams *p)
 
   /* 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;
+  if(p->table->size==0 || p->table->array==NULL || 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,
diff --git a/lib/blank.c b/lib/blank.c
index 4de4de1a..ccbdcc06 100644
--- a/lib/blank.c
+++ b/lib/blank.c
@@ -569,9 +569,16 @@ gal_blank_flag(gal_data_t *input)
   gal_data_t *out;
   char **str=input->array, **strf=str+input->size;
 
-  /* The datasets may be empty. In this case the output should also be
-     empty (we can have tables and images with 0 rows or pixels!). */
-  if(input->size==0 || input->array==NULL) return input;
+  /* The datasets may be empty. In this case, the output should also be
+     empty, but with the standard 'uint8' type of a flag (we can have
+     tables and images with 0 rows or pixels!). */
+  if(input->size==0 || input->array==NULL)
+    {
+      out=gal_data_alloc_empty(input->ndim, input->minmapsize,
+                               input->quietmmap);
+      out->type=GAL_TYPE_UINT8;
+      return out;
+    }
 
   /* Do all the checks and allocations if a blank is actually present! */
   if( gal_blank_present(input, 0) )
@@ -733,6 +740,11 @@ gal_blank_flag_remove(gal_data_t *input, gal_data_t *flag)
     error(EXIT_FAILURE, 0, "%s: the 'flag' argument doesn't have the same "
           "size as the 'input' argument", __func__);
 
+  /* If there is no elements in the input or the flag (we have already
+     confirmed that they are the same size), then just return (nothing is
+     necessary to do). */
+  if(flag->size==0 || flag->array==NULL) return;
+
   /* Shift all non-blank elements to the start of the array. */
   switch(input->type)
     {
@@ -927,7 +939,6 @@ gal_blank_remove_rows(gal_data_t *columns, gal_list_sizet_t 
*column_indexs)
   /* Now that the flags have been set, remove the rows. */
   for(tmp=columns; tmp!=NULL; tmp=tmp->next)
     gal_blank_flag_remove(tmp, flag);
-
   /* For a check.
   double *d1=columns->array, *d2=columns->next->array;
   for(i=0;i<columns->size;++i)



reply via email to

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