gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 01775ce: Library WCS: coordinate conversions c


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 01775ce: Library WCS: coordinate conversions check if WCS isn't NULL
Date: Thu, 10 Oct 2019 15:53:09 -0400 (EDT)

branch: master
commit 01775ce92b3821e44a2c494301e14923a49466f7
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Library WCS: coordinate conversions check if WCS isn't NULL
    
    Until now, there was no actual check in the two `gal_wcs_img_to_world' and
    `gal_wcs_world_to_img' functions to see if the input WCS pointer actually
    points to something! As a result, when the library user forgot to read the
    input file's WCS, they would get a segmentation fault.
    
    With this commit a check has been added and the calling program will abort
    when the input WCS is NULL.
---
 lib/wcs.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/wcs.c b/lib/wcs.c
index 8ca6cf6..e1e8526 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -847,6 +847,10 @@ wcs_convert_sanity_check_alloc(gal_data_t *coords, struct 
wcsprm *wcs,
   gal_data_t *tmp;
   size_t ndim=0, firstsize=0, size=coords->size;
 
+  /* Make sure a WCS structure is actually given. */
+  if(wcs==NULL)
+    error(EXIT_FAILURE, 0, "%s: input WCS structure is NULL", func);
+
   for(tmp=coords; tmp!=NULL; tmp=tmp->next)
     {
       /* Count how many coordinates are given. */
@@ -961,13 +965,13 @@ gal_data_t *
 gal_wcs_world_to_img(gal_data_t *coords, struct wcsprm *wcs, int inplace)
 {
   gal_data_t *out;
-  int status, *stat=NULL, ncoord=coords->size, nelem=wcs->naxis;
+  int status, *stat=NULL, ncoord=coords->size, nelem;
   double *phi=NULL, *theta=NULL, *world=NULL, *pixcrd=NULL, *imgcrd=NULL;
 
   /* Some sanity checks. */
   wcs_convert_sanity_check_alloc(coords, wcs, __func__, &stat, &phi, &theta,
                                  &world, &pixcrd, &imgcrd);
-
+  nelem=wcs->naxis; /* We have to make sure a WCS is given first. */
 
   /* Write the values from the input list of separate columns into a single
      array (WCSLIB input). */
@@ -1021,12 +1025,13 @@ gal_data_t *
 gal_wcs_img_to_world(gal_data_t *coords, struct wcsprm *wcs, int inplace)
 {
   gal_data_t *out;
-  int status, *stat=NULL, ncoord=coords->size, nelem=wcs->naxis;
+  int status, *stat=NULL, ncoord=coords->size, nelem;
   double *phi=NULL, *theta=NULL, *world=NULL, *pixcrd=NULL, *imgcrd=NULL;
 
   /* Some sanity checks. */
   wcs_convert_sanity_check_alloc(coords, wcs, __func__, &stat, &phi, &theta,
                                  &world, &pixcrd, &imgcrd);
+  nelem=wcs->naxis; /* We have to make sure a WCS is given first. */
 
 
   /* Write the values from the input list of separate columns into a single



reply via email to

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