gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master af7c78b 1/2: Query: avoid segmentation fault w


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master af7c78b 1/2: Query: avoid segmentation fault with NED and no dataset
Date: Sun, 4 Jul 2021 20:40:24 -0400 (EDT)

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

    Query: avoid segmentation fault with NED and no dataset
    
    Until now, when NED was queried without any dataset, Query would crash with
    a segmentation fault! But it should have printed a warning about the
    available datasets and how to access them (like any other database).
    
    With this commit, the source of the problem was found and fixed (it was
    introduced after we added the 'extinction' dataset to NED).
---
 NEWS            |  2 +-
 bin/query/ned.c | 57 ++++++++++++++++++++++++++++++++++-----------------------
 bin/query/ui.c  |  4 +++-
 3 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/NEWS b/NEWS
index 9afb491..928bb57 100644
--- a/NEWS
+++ b/NEWS
@@ -41,7 +41,7 @@ See the end of the file for license conditions.
   bug #60778: Brightness error not NaN when all STD pixels are blank,
               this bug was reported by Zahra Sharbaf.
   bug #60826: Arithmetic won't delete existing file with tofile operators.
-
+  bug #60881: Query segmentation fault when NED is called without a dataset.
 
 
 
diff --git a/bin/query/ned.c b/bin/query/ned.c
index 80a9bae..87ba910 100644
--- a/bin/query/ned.c
+++ b/bin/query/ned.c
@@ -44,36 +44,47 @@ ned_sanity_checks(struct queryparams *p)
   /* Set the summarized names. */
   if(p->datasetstr)
     {
+      /* Correct the dataset name if 'objdir' is given. */
       if( !strcmp(p->datasetstr, "objdir") )
         {
           free(p->datasetstr);
           gal_checkset_allocate_copy("NEDTAP.objdir", &p->datasetstr);
         }
-    }
 
-  /* Database-specific checks. For example, if we should use TAP or
-     not. Note that the user may give 'NEDTAP.objdir', so we can't use the
-     'if' above (for expanding summarized names). */
-  if( !strcmp(p->datasetstr, "NEDTAP.objdir") )
-    p->usetap=1;
-  else if( !strcmp(p->datasetstr, "extinction") )
-    {
-      /* Crash for options that are not compatible with extinction. */
-      if( p->radius || p->width || p->range || p->noblank || p->columns
-          || p->head!=GAL_BLANK_SIZE_T || p->sort )
-        error(EXIT_FAILURE, 0, "NED's extinction calculator returns "
-              "the galactic extinction for a single point (in multiple "
-              "filters), therefore the following options are not "
-              "acceptable with it: '--radius', '--width', '--range', "
-              "'--noblank', '--column', '--head' and '--sort'");
-
-      /* Make sure that '--center' is given. */
-      if(p->center==NULL)
-        error(EXIT_FAILURE, 0, "no coordinate specified! Please use "
-              "'--center' to specify the RA and Dec (in J2000) of "
-              "your desired coordinate, for example "
-              "--center=10.68458,41.269166");
+      /* Database-specific checks. For example, if we should use TAP or
+         not. Note that the user may give 'NEDTAP.objdir', so we can't use
+         the 'if' above (for expanding summarized names). */
+      if( !strcmp(p->datasetstr, "NEDTAP.objdir") )
+        p->usetap=1;
+      else if( !strcmp(p->datasetstr, "extinction") )
+        {
+          /* Crash for options that are not compatible with extinction. */
+          if( p->radius || p->width || p->range || p->noblank || p->columns
+              || p->head!=GAL_BLANK_SIZE_T || p->sort )
+            error(EXIT_FAILURE, 0, "NED's extinction calculator returns "
+                  "the galactic extinction for a single point (in multiple "
+                  "filters), therefore the following options are not "
+                  "acceptable with it: '--radius', '--width', '--range', "
+                  "'--noblank', '--column', '--head' and '--sort'");
+
+          /* Make sure that '--center' is given. */
+          if(p->center==NULL)
+            error(EXIT_FAILURE, 0, "no coordinate specified! Please use "
+                  "'--center' to specify the RA and Dec (in J2000) of "
+                  "your desired coordinate, for example "
+                  "--center=10.68458,41.269166");
+        }
     }
+  else
+    error(EXIT_FAILURE, 0, "no dataset specified! Query only recognizes "
+          "two datasets for NED: 'objdir' and 'extinction'. 'objdir' "
+          "is in the IVOA Table Access Protocol (TAP) format, so you "
+          "can see its available columns before downloading the actual "
+          "data (to only download the small sub-set you need) with this "
+          "command: 'astquery %s --dataset=objdir --info'. However, the "
+          "'extinction' catalog isn't TAP-based, so the '--info' option "
+          "isn't supported (but by its nature, the size of the "
+          "extinction catalog is very small)", p->databasestr);
 
   /* Currently NED only has a single table for TAP access, so warn the
      users about this if they ask for any other table. */
diff --git a/bin/query/ui.c b/bin/query/ui.c
index e03fe4f..1cc7fa1 100644
--- a/bin/query/ui.c
+++ b/bin/query/ui.c
@@ -406,8 +406,10 @@ ui_read_check_only_options(struct queryparams *p)
   gal_checkset_writable_remove(p->cp.output, p->cp.keep,
                                p->cp.dontdelete);
 
-  /* Set the suffix of the default names. */
+  /* Set the suffix of the default download names for NED (since extinction
+     is given only in VOTable, with an '.xml' suffix). */
   if( p->database==QUERY_DATABASE_NED
+      && p->datasetstr
       && !strcmp(p->datasetstr, "extinction") )
     {
       suffix=".xml";



reply via email to

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