Merge release-4-5-patches into release-4-6
[alexxy/gromacs.git] / src / gmxlib / selection / evaluate.c
index 1913adad26fda89ea17d07a61a697e07dcbe1fea..8e48c6a708383a61a1b886665f6112e1115b3d8b 100644 (file)
@@ -51,6 +51,7 @@
 #include <maths.h>
 #include <smalloc.h>
 #include <vec.h>
+#include <assert.h>
 
 #include <indexutil.h>
 #include <poscalc.h>
@@ -1076,13 +1077,13 @@ int
 _gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t *data, t_selelem *sel,
                              gmx_ana_index_t *g)
 {
-    t_selelem  *left, *right;
     int         n, i, i1, i2;
     real        lval, rval=0., val=0.;
     int         rc;
+    gmx_bool    bArithNeg;
 
-    left  = sel->child;
-    right = left->next;
+    t_selelem  *const left  = sel->child;
+    t_selelem  *const right = left->next;
 
     if (left->mempool)
     {
@@ -1104,10 +1105,13 @@ _gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t *data, t_selelem *sel,
 
     n = (sel->flags & SEL_SINGLEVAL) ? 1 : g->isize;
     sel->v.nr = n;
+
+    bArithNeg = (sel->u.arith.type == ARITH_NEG);
+    assert(right || bArithNeg);
     for (i = i1 = i2 = 0; i < n; ++i)
     {
         lval = left->v.u.r[i1];
-        if (sel->u.arith.type != ARITH_NEG)
+        if (!bArithNeg)
         {
             rval = right->v.u.r[i2];
         }
@@ -1125,7 +1129,7 @@ _gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t *data, t_selelem *sel,
         {
             ++i1;
         }
-        if (sel->u.arith.type != ARITH_NEG && !(right->flags & SEL_SINGLEVAL))
+        if (!bArithNeg && !(right->flags & SEL_SINGLEVAL))
         {
             ++i2;
         }