[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master ca24f18 2/3: Arithmetic: all operand pointers
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master ca24f18 2/3: Arithmetic: all operand pointers initialized while parsing |
Date: |
Mon, 11 Mar 2019 16:54:23 -0400 (EDT) |
branch: master
commit ca24f18d7b390da57cf62de55f236814047c51cf
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Arithmetic: all operand pointers initialized while parsing
Until now, we were not initializing the operand pointers after finishing
with them. This could cause conflicts (segmentation faults) in certain
scenarios. With this commit, before starting to set the operand pointers,
we initialize them to NULL.
---
bin/arithmetic/arithmetic.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index b221ce9..bfa33e0 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -907,8 +907,8 @@ reversepolish(struct arithmeticparams *p)
int op=0, nop=0;
unsigned int numop, i;
gal_list_str_t *token;
+ gal_data_t *d1, *d2, *d3;
char *hdu, *filename, *printnum;
- gal_data_t *d1=NULL, *d2=NULL, *d3=NULL;
int flags = ( GAL_ARITHMETIC_INPLACE | GAL_ARITHMETIC_FREE
| GAL_ARITHMETIC_NUMOK );
@@ -942,7 +942,6 @@ reversepolish(struct arithmeticparams *p)
operands_add(p, NULL, d1);
else
{
-
/* Order is the same as in the manual. */
/* Simple arithmetic operators. */
if (!strcmp(token->v, "+" ))
@@ -1097,14 +1096,15 @@ reversepolish(struct arithmeticparams *p)
{ op=ARITHMETIC_OP_COLLAPSE_MEAN; nop=0; }
else if (!strcmp(token->v, "collapse-number"))
{ op=ARITHMETIC_OP_COLLAPSE_NUMBER; nop=0; }
-
-
- /* Finished checks with known operators */
else
error(EXIT_FAILURE, 0, "the argument \"%s\" could not be "
"interpretted as a file name, named dataset, number, or "
"operator", token->v);
+ /* Initialize all the operand pointers (they may be remaining
+ from previous operators and we don't want them to cause
+ confusion. */
+ d1 = d2 = d3 = NULL;
/* See if the arithmetic library must be called or not. */
if(nop)
@@ -1138,7 +1138,6 @@ reversepolish(struct arithmeticparams *p)
integer number, we will use that to construct a linked
list of any number of operands within the single `d1'
pointer. */
- d1=NULL;
numop=pop_number_of_operands(p, op, token->v, &d2);
for(i=0;i<numop;++i)
gal_list_data_add(&d1, operands_pop(p, token->v));