gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5336d5c 024/125: Small but important correctio


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5336d5c 024/125: Small but important corrections
Date: Sun, 23 Apr 2017 22:36:29 -0400 (EDT)

branch: master
commit 5336d5c3a639ef01eb0e6adf886e04d67f784628
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Small but important corrections
    
    Some small points that had been missed during writing of the code has been
    corrected. These are mostly one-liners, but would cause crashes or infinite
    loops.
---
 bin/arithmetic/arithmetic.c | 2 --
 bin/arithmetic/operands.c   | 9 ++++-----
 lib/data-arithmetic-other.c | 3 +--
 lib/data.c                  | 4 ++--
 4 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 5b75361..8e4895a 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -284,7 +284,6 @@ reversepolish(struct imgarithparams *p)
           else if (!strcmp(token->v, "double"))
             { op=GAL_DATA_OPERATOR_TO_DOUBLE;     nop=1;  }
 
-
           /* Finished checks with known operators */
           else
             error(EXIT_FAILURE, 0, "the argument \"%s\" could not be "
@@ -381,7 +380,6 @@ reversepolish(struct imgarithparams *p)
   gal_data_free(d1);
   free(p->refdata.dsize);
 
-
   /* Clean up. Note that the tokens were taken from the command-line
      arguments, so the string within each token linked list must not be
      freed. */
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index d18754e..eea13c9 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -60,11 +60,10 @@ add_operand(struct imgarithparams *p, char *filename, 
gal_data_t *data)
 {
   struct operand *newnode;
 
-  /* Some operators might not actually return any dataset (for example the
-     multi-operand datasets when the number of operands is 0, which can
-     happen in a script), in such cases, we shouldn't add anything to the
-     stack. */
-  if(data)
+  /* Some operators might not actually return any dataset (data=NULL), in
+     such cases filename will also be NULL (since the operand was not added
+     from the command-line). So, we shouldn't add anything to the stack. */
+  if(data || filename)
     {
       /* Allocate space for the new operand. */
       errno=0;
diff --git a/lib/data-arithmetic-other.c b/lib/data-arithmetic-other.c
index 8c7d9bb..ed12c7d 100644
--- a/lib/data-arithmetic-other.c
+++ b/lib/data-arithmetic-other.c
@@ -47,7 +47,7 @@ gal_data_t *
 data_arithmetic_change_type(gal_data_t *data, int operator,
                             unsigned char flags)
 {
-  int type=0;
+  int type=-1;
   gal_data_t *out;
 
   /* Set the output type. */
@@ -64,7 +64,6 @@ data_arithmetic_change_type(gal_data_t *data, int operator,
     case GAL_DATA_OPERATOR_TO_LONGLONG: type=GAL_DATA_TYPE_LONGLONG; break;
     case GAL_DATA_OPERATOR_TO_FLOAT:    type=GAL_DATA_TYPE_FLOAT;    break;
     case GAL_DATA_OPERATOR_TO_DOUBLE:   type=GAL_DATA_TYPE_DOUBLE;   break;
-
     default:
       error(EXIT_FAILURE, 0, "operator value of %d not recognized in "
             "`data_arithmetic_change_type'", operator);
diff --git a/lib/data.c b/lib/data.c
index 41dd5fc..0086537 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -1011,7 +1011,7 @@ gal_data_has_blank(gal_data_t *data)
             "datatype, please get in touch with us to implement it.");
 
     case GAL_DATA_TYPE_UCHAR:
-      do if(*uc==GAL_DATA_BLANK_UCHAR) return 1; while(uc<ucf);
+      do if(*uc++==GAL_DATA_BLANK_UCHAR) return 1; while(uc<ucf);
       break;
 
 
@@ -2003,7 +2003,7 @@ gal_data_arithmetic(int operator, unsigned char flags, 
...)
     case GAL_DATA_OPERATOR_TO_FLOAT:
     case GAL_DATA_OPERATOR_TO_DOUBLE:
       d1 = va_arg(va, gal_data_t *);
-      data_arithmetic_change_type(d1, operator, flags);
+      out=data_arithmetic_change_type(d1, operator, flags);
       break;
 
 



reply via email to

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