gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5022d787: Fits: added sanity check when readin


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5022d787: Fits: added sanity check when reading keyword names
Date: Thu, 4 Aug 2022 09:38:08 -0400 (EDT)

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

    Fits: added sanity check when reading keyword names
    
    Until now (the previous commit), we would just stop the loop (that parses
    all the keywords for their names) when the 'status' was non-zero. In
    expected scenarios (where the only non-zero exit status is
    'KEY_OUT_BOUNDS', this is fine. But we hadn't accounted for any other
    possible exit status (due to some unexpected error).
    
    With this commit, a check has been added that will stop the loop if the
    exit status is not zero or 'KEY_OUT_BOUND'.
---
 bin/fits/keywords.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index ce694d92..9eca698a 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -331,6 +331,13 @@ keywords_list_key_names(struct fitsparams *p, fitsfile 
*fptr)
       /* Read the (next) keyword. */
       fits_read_keyn(fptr, i++, keyname, value, comment, &status);
 
+      /* If there is a problem (status is non-zero _and_ not
+         'KEY_OUT_BOUNDS'), abort with an error message. When 'status'
+         becomes 'KEY_OUT_BOUNDS', we have reached the end, so that isn't a
+         problem. */
+      if(status && status!=KEY_OUT_BOUNDS)
+        gal_fits_io_error(status, NULL);
+
       /* Print the keyword name (if its not empty!). */
       if( keyname[0]!='\0' ) printf("%s\n", keyname);
     }



reply via email to

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