gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master acf8910: MakeProfiles: ignore --kernel option


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master acf8910: MakeProfiles: ignore --kernel option when already given
Date: Sat, 5 Dec 2020 18:58:36 -0500 (EST)

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

    MakeProfiles: ignore --kernel option when already given
    
    Until now, if the '--kernel' option was called more than once, the last
    instance would be used, not the first (as expected by Gnuastro's option
    precedence). I also noticed that there is no sanity check on numbers given
    after the profile name. So for example if the user mistakenly gave
    '--kernel=kernel.fits' (like other programs), it would give a segmentation
    fault.
    
    With this commit after the first instance of '--kernel' has been
    interpretted, any later instance will be ignored. Also, if nothing is given
    after the main string, an error will be printed.
    
    This fixes bug #59625.
---
 NEWS            |  1 +
 bin/mkprof/ui.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/NEWS b/NEWS
index 479e37e..1b81997 100644
--- a/NEWS
+++ b/NEWS
@@ -175,6 +175,7 @@ See the end of the file for license conditions.
   bug #59371: MakeCatalog crash with clumps on non-contiguous object labels.
   bug #59400: CosmicCalculator fails --printparams when redshift isn't given.
   bug #59459: Unclear WCS when both PC and CD exist in input, but conflict.
+  bug #59625: MakeProfiles uses last --kernel, if it is called more than once.
 
 
 
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index 9e321c0..afd17f9 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -332,6 +332,10 @@ ui_parse_kernel(struct argp_option *option, char *arg,
     }
   else
     {
+      /* If the kernel has already been given, ignore it (the previously
+         read value has higher precedence). */
+      if( *(gal_data_t **)(option->value) ) return NULL;
+
       /* The first part of 'arg' (before the first comma) is not
          necessarily a number. So we need to separate the first part from
          the rest.*/
@@ -340,9 +344,18 @@ ui_parse_kernel(struct argp_option *option, char *arg,
       arg = (*c=='\0') ? NULL : c+1;  /* the 'point' profile doesn't need */
       *c='\0';                        /* any numbers.                     */
 
+      /* Make sure something exists after the name of the profile. */
+      if(arg==NULL)
+        error(EXIT_FAILURE, 0, "the kernel option value couldn't be "
+              "parsed in the expected format: one name (of a profile), "
+              "followed by some numbers defining that profile. See the "
+              "description of '--kernel' in the manual (with the 'info "
+              "astmkprof' command) for the meaning of the numbers");
 
       /* Read the parameters. */
       kernel=gal_options_parse_list_of_numbers(arg, filename, lineno);
+
+      /* Put the kernel dataset into the main program structure. */
       *(gal_data_t **)(option->value) = kernel;
 
 



reply via email to

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