gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 0cddec3: Library (fits): gal_fits_name_save_as


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 0cddec3: Library (fits): gal_fits_name_save_as_string works with stdin
Date: Wed, 6 Mar 2019 15:06:35 -0500 (EST)

branch: master
commit 0cddec3d7d7bddcc5fbbe3ddc4e0160b768a8092
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Library (fits): gal_fits_name_save_as_string works with stdin
    
    Until now, when this function was given a filename that is `NULL', it would
    cause a segmentation fault in the program. But when the input is from the
    standard input, the `filename' will be `NULL'. So it now returns `stdin' in
    such cases.
    
    This bug was reported by Elham Eftekhari.
    
    This fixes bug #55845.
---
 NEWS              |  1 +
 bin/mkprof/ui.c   |  1 +
 doc/gnuastro.texi | 11 +++++++----
 lib/fits.c        | 15 +++++++++++----
 lib/table.c       |  4 ++--
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index 6e6fca6..27d1b0b 100644
--- a/NEWS
+++ b/NEWS
@@ -140,6 +140,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   bug #55740: Diamond shapes in nearst-ngb interpolation affecting NoiseChisel.
   bug #55763: Crop not keeping Blank pixels on unsigned types.
   bug #55844: WCS library (and thus all programs) can't deal with CROTAi 
values.
+  bug #55845: Crash when necessary column not found from standard input.
 
 
 
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index ca6c13f..9117a6c 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -1561,6 +1561,7 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
mkprofparams *p)
   /* Read/allocate all the necessary starting arrays. */
   ui_preparations(p);
 
+
   /* Print introductory information. */
   ui_print_intro(p);
 }
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 6013bcc..6f20a18 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -25803,10 +25803,13 @@ suffix doesn't have to start with address@hidden': 
this function will return
 
 @deftypefun {char *} gal_fits_name_save_as_string (char @code{*filename}, char 
@code{*hdu})
 If the name is a FITS name, then put a @code{(hdu: ...)} after it and
-return the string. If it isn't a FITS file, just print the name. Note that
-the space is allocated. This function is useful when you want to report a
-random file to the user which may be FITS or not (for a FITS file, simply
-the filename is not enough, the HDU is also necessary).
+return the string. If it isn't a FITS file, just print the name, if
address@hidden, then return the string @code{stdin}. Note that the
+output string's space is allocated.
+
+This function is useful when you want to report a random file to the user
+which may be FITS or not (for a FITS file, simply the filename is not
+enough, the HDU is also necessary).
 @end deftypefun
 
 
diff --git a/lib/fits.c b/lib/fits.c
index 994a619..0261c30 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -147,12 +147,19 @@ char *
 gal_fits_name_save_as_string(char *filename, char *hdu)
 {
   char *name;
-  if( gal_fits_name_is_fits(filename) )
+
+  /* Small sanity check. */
+  if(filename==NULL)
+    gal_checkset_allocate_copy("stdin", &name);
+  else
     {
-      if( asprintf(&name, "%s (hdu: %s)", filename, hdu)<0 )
-        error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+      if( gal_fits_name_is_fits(filename) )
+        {
+          if( asprintf(&name, "%s (hdu: %s)", filename, hdu)<0 )
+            error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
+        }
+      else gal_checkset_allocate_copy(filename, &name);
     }
-  else gal_checkset_allocate_copy(filename, &name);
   return name;
 }
 
diff --git a/lib/table.c b/lib/table.c
index afc3d21..82e02da 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -211,7 +211,7 @@ table_set_strcheck(gal_data_t *col, int searchin)
 
 
 static gal_list_sizet_t *
-make_list_of_indexs(gal_list_str_t *cols, gal_data_t *allcols,
+table_list_of_indexs(gal_list_str_t *cols, gal_data_t *allcols,
                     size_t numcols, int searchin, int ignorecase,
                     char *filename, char *hdu, size_t *colmatch)
 {
@@ -420,7 +420,7 @@ gal_table_read(char *filename, char *hdu, gal_list_str_t 
*lines,
   if(allcols==NULL) return NULL;
 
   /* Get the list of indexs in the same order as the input list */
-  indexll=make_list_of_indexs(cols, allcols, numcols, searchin,
+  indexll=table_list_of_indexs(cols, allcols, numcols, searchin,
                               ignorecase, filename, hdu, colmatch);
 
   /* Depending on the table format, read the columns into the output



reply via email to

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