gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 86c0e0e 2/2: Library (options.h): accounting f


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 86c0e0e 2/2: Library (options.h): accounting for non-sexagesimal colons in values
Date: Sat, 18 Dec 2021 14:56:48 -0500 (EST)

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

    Library (options.h): accounting for non-sexagesimal colons in values
    
    Until now, when 'gal_options_parse_list_of_numbers' was given a string like
    '4:5' (extracted for example from Table's '--range=NAME,4:5') it would
    abort, complaining that '4:5' can't be parsed as a number. This is the
    result of a recent change in this function to allow reading sexagesimal
    coordinates for example '01:23:45.67'.
    
    With this commit, the issue was fixed by avoiding the stopping of the
    program when the first un-parsed character was a ':'.
    
    It wasn't registered as a bug because it was due to a recent addition
    (after version 0.16).
    
    This issue was reported by Sepideh Eskandarlou.
---
 lib/options.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/options.c b/lib/options.c
index fd89456..70c572f 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -827,11 +827,20 @@ gal_options_parse_list_of_numbers(char *string, char 
*filename, size_t lineno)
           tmp=strtod(c, &tailptr);
           if(*tailptr!=',' && *tailptr!='/' && *tailptr!='\0')
             {
+              /* See if the user has given a sexagesimal value (that can't
+                 be easily read with 'strtod'). */
               ttmp=gal_options_read_sexagesimal(num%2, c, &tailptr);
               if(isnan(ttmp))
-                error_at_line(EXIT_FAILURE, 0, filename, lineno, "the "
-                              "'%s' component of '%s' couldn't be parsed "
-                              "as a usable number", c, string);
+                {
+                  /* This happens in cases like the values to Table's
+                     '--range=NAME,5:10'. In such cases, we do have a
+                     colon, but don't have a sexagesimal number. So we
+                     shouldn't abort the program! */
+                  if(tailptr[0]!=':')
+                    error_at_line(EXIT_FAILURE, 0, filename, lineno, "the "
+                                  "'%s' component of '%s' couldn't be parsed "
+                                  "as a usable number", c, string);
+                }
               else tmp=ttmp;
             }
 



reply via email to

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