[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master bb15a99e: Arithmetic: tofilefree- operator cor
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master bb15a99e: Arithmetic: tofilefree- operator correctly deals with directories |
Date: |
Fri, 11 Aug 2023 08:48:03 -0400 (EDT) |
branch: master
commit bb15a99ea79dc68e1c874aed1c77e8b2ec9f8cc7
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Arithmetic: tofilefree- operator correctly deals with directories
Until now, when the 'tofilefree-' operator of Arithmetic was given a file
name that included a directory, it would crash. This was because the
proper length of the string was not been checked.
With this commit, the problem is solved by using the length
'OPERATOR_PREFIX_LENGTH_TOFILEFREE' instead of the mistaken
'OPERATOR_PREFIX_LENGTH_TOFILE' length!
This fixes bug #64544.
---
NEWS | 2 ++
bin/arithmetic/arithmetic.c | 2 +-
bin/arithmetic/ui.c | 32 +++++++++++++++++---------------
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/NEWS b/NEWS
index a5bdb100..f51fa89b 100644
--- a/NEWS
+++ b/NEWS
@@ -172,6 +172,8 @@ See the end of the file for license conditions.
bug #64431: gal_wcs_to_cd does not account for altlin==3. Reported by
Colin Orion Chandler.
bug #64541: Segment's --keepmaxnearriver has no effect.
+ bug #64544: Arithmetic crashes with tofilefree operator value has a
+ directory.
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 1de51e9e..7bcfbd64 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -1774,7 +1774,7 @@ reversepolish(struct arithmeticparams *p)
OPERATOR_PREFIX_LENGTH_TOFILE) )
arithmetic_tofile(p, token->v, 0);
else if( !strncmp(OPERATOR_PREFIX_TOFILEFREE, token->v,
- OPERATOR_PREFIX_LENGTH_TOFILE) )
+ OPERATOR_PREFIX_LENGTH_TOFILEFREE) )
arithmetic_tofile(p, token->v, 1);
else if( !strncmp(token->v, GAL_ARITHMETIC_SET_PREFIX,
GAL_ARITHMETIC_SET_PREFIX_LENGTH) )
diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index a0788a35..2aca747c 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -255,15 +255,16 @@ static void
ui_check_options_and_arguments(struct arithmeticparams *p)
{
gal_list_str_t *token, *hdu;
- char *filename, *basename=NULL;
size_t nummultiext=0, numhdus=0;
+ char *tofilename=NULL, *basename=NULL;
struct gal_options_common_params *cp=&p->cp;
/* First, make sure that any tokens are actually given. */
if(p->tokens==NULL)
- error(EXIT_FAILURE, 0, "no input tokens. Please specify a filename or "
- "number (as operands) along with operator(s) as input. Please run "
- "any of the following commands for more information.\n\n"
+ error(EXIT_FAILURE, 0, "no input tokens. Please specify a file name "
+ "or number (as operands) along with operator(s) as input. "
+ "Please run any of the following commands for more "
+ "information.\n\n"
" $ astarithmetic --help # Short info.\n"
" $ info astarithmetic # Full invocation "
"documentation.\n");
@@ -292,22 +293,23 @@ ui_check_options_and_arguments(struct arithmeticparams *p)
/* Strings given to the 'tofile' or 'tofilefree' operators are also
considered as outputs and we should delete them before starting
the parse. */
- if( strncmp(OPERATOR_PREFIX_TOFILE, token->v,
- OPERATOR_PREFIX_LENGTH_TOFILE)==0
- || strncmp(OPERATOR_PREFIX_TOFILEFREE, token->v,
- OPERATOR_PREFIX_LENGTH_TOFILEFREE)==0 )
- {
- filename=&token->v[ OPERATOR_PREFIX_LENGTH_TOFILE ];
- gal_checkset_writable_remove(filename, basename, cp->keep,
- cp->dontdelete);
- }
+ tofilename = ( strncmp(OPERATOR_PREFIX_TOFILE, token->v,
+ OPERATOR_PREFIX_LENGTH_TOFILE)==0
+ ? &token->v[ OPERATOR_PREFIX_LENGTH_TOFILE ]
+ : ( strncmp(OPERATOR_PREFIX_TOFILEFREE, token->v,
+ OPERATOR_PREFIX_LENGTH_TOFILEFREE)==0
+ ? &token->v[ OPERATOR_PREFIX_LENGTH_TOFILEFREE ]
+ : NULL ) );
+ if(tofilename)
+ gal_checkset_writable_remove(tofilename, basename, cp->keep,
+ cp->dontdelete);
/* This may be a simple filename. */
else
{
/* This token is a file, count how many mult-extension files we
- have and use the first to set the output filename (if it has
- not been set). */
+ have and use the first to set the output file's name (if it
+ has not been set). */
if( gal_array_name_recognized(token->v)
|| gal_fits_file_recognized(token->v) )
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master bb15a99e: Arithmetic: tofilefree- operator correctly deals with directories,
Mohammad Akhlaghi <=