[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 44fc4d1: gal_options_check_version also return
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 44fc4d1: gal_options_check_version also returns version |
Date: |
Tue, 13 Feb 2018 08:59:26 -0500 (EST) |
branch: master
commit 44fc4d114b32d00dd6a7c791fd84f8b1a87c88d7
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
gal_options_check_version also returns version
Until now, we had not considered the fact that with the `-P' option, a user
might want to print the version information also (if the `onlyversion'
option is called). Therefore, in such cases, `arg' (first input to
`gal_options_check_version' was NULL and we would get a segmentation
fault). This has been fixed now and this function also returns an allocated
version string to feed into the printing function.
This fixes bug #53142.
---
NEWS | 2 ++
lib/options.c | 72 +++++++++++++++++++++++++++++++++++++----------------------
2 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/NEWS b/NEWS
index f0c4a7b..800152d 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ GNU Astronomy Utilities NEWS -*-
outline -*-
Configure time CPPFLAGS and LDFLAGS don't pass to BuildProgram (bug #53122).
+ Crash when printing values with the `--onlyversion' option (bug #53142).
+
diff --git a/lib/options.c b/lib/options.c
index 46e2743..9fb9e48 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -179,35 +179,53 @@ void *
gal_options_check_version(struct argp_option *option, char *arg,
char *filename, size_t lineno, void *junk)
{
+ char *str;
+
+ /* First see if we are reading or writing. */
+ if(lineno==-1)
+ {
+ /* Note that `PACKAGE_VERSION' is a static string. But the output
+ must be an allocated string so we can free it. */
+ gal_checkset_allocate_copy(PACKAGE_VERSION, &str);
+ return str;
+ }
+
/* Check if the given value is different from this version. */
- if( strcmp(arg, PACKAGE_VERSION) )
+ else
{
- /* Print an error message and abort. */
- error_at_line(EXIT_FAILURE, 0, filename, lineno, "version mis-match: "
- "you are running GNU Astronomy Utilities (Gnuastro) "
- "version `%s'. However, the `onlyversion' option is set "
- "to version `%s'.\n\n"
- "This was probably done for reproducibility. Therefore, "
- "manually removing, or changing, the option value might "
- "produce errors or unexpected results. It is thus "
- "strongly advised to build Gnuastro %s and re-run this "
- "command/script.\n\n"
- "You can download previously released tar-balls from the "
- "following URLs respectively:\n\n"
- " Stable (version format: X.Y): "
- "http://ftpmirror.gnu.org/gnuastro\n"
- " Alpha (version format: X.Y.A-B): "
- "http://alpha.gnu.org/gnu/gnuastro\n\n"
- "Alternatively, you can clone Gnuastro, checkout the "
- "respective commit (from the version number), then "
- "bootstrap and build it. Please run the following "
- "command for more information:\n\n"
- " $ info gnuastro \"Version controlled source\"\n",
- PACKAGE_VERSION, arg, arg);
-
- /* Just to avoid compiler warnings for unused variables. The program
- will never reach this point! */
- arg=filename=NULL; lineno=0; option=NULL; junk=NULL;
+ if(arg==NULL)
+ error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
+ "the problem. The value to `arg' is NULL", __func__,
+ PACKAGE_BUGREPORT);
+ else if( strcmp(arg, PACKAGE_VERSION) )
+ {
+ /* Print an error message and abort. */
+ error_at_line(EXIT_FAILURE, 0, filename, lineno, "version "
+ "mis-match: you are running GNU Astronomy Utilities "
+ "(Gnuastro) version `%s'. However, the `onlyversion' "
+ "option is set to version `%s'.\n\n"
+ "This was probably done for reproducibility. "
+ "Therefore, manually removing, or changing, the "
+ "option value might produce errors or unexpected "
+ "results. It is thus strongly advised to build "
+ "Gnuastro %s and re-run this command/script.\n\n"
+ "You can download previously released tar-balls "
+ "from the following URLs respectively:\n\n"
+ " Stable (version format: X.Y): "
+ "http://ftpmirror.gnu.org/gnuastro\n"
+ " Alpha (version format: X.Y.A-B): "
+ "http://alpha.gnu.org/gnu/gnuastro\n\n"
+ "Alternatively, you can clone Gnuastro, checkout the "
+ "respective commit (from the version number), then "
+ "bootstrap and build it. Please run the following "
+ "command for more information:\n\n"
+ " $ info gnuastro \"Version controlled source\"\n",
+ PACKAGE_VERSION, arg, arg);
+
+ /* Just to avoid compiler warnings for unused variables. The program
+ will never reach this point! */
+ arg=filename=NULL; lineno=0; option=NULL; junk=NULL;
+ }
}
return NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 44fc4d1: gal_options_check_version also returns version,
Mohammad Akhlaghi <=