[balsa] Check negated conditions when comparing



commit 15e20a0810c5fa38b039f8b4249e4c44c7c830d7
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Dec 20 12:37:05 2009 -0500

    Check negated conditions when comparing

 ChangeLog               |    7 +++++++
 libbalsa/filter-funcs.c |   12 ++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 702b3a0..58094ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-20  Peter Bloomfield
+
+	* libbalsa/filter-funcs.c (lbcond_new): save negated as 0 or 1,
+	to simplify later comparison.
+	(libbalsa_condition_compare): return FALSE if negate differs;
+	drop now-redundant test for flag conditions.
+
 2009-12-19  Peter Bloomfield
 
 	* libbalsa/filter-funcs.c (libbalsa_condition_compare):
diff --git a/libbalsa/filter-funcs.c b/libbalsa/filter-funcs.c
index 9610b33..df80acf 100644
--- a/libbalsa/filter-funcs.c
+++ b/libbalsa/filter-funcs.c
@@ -78,7 +78,7 @@ lbcond_new(ConditionMatchType type, gboolean negated)
 
     cond = g_new(LibBalsaCondition, 1);
     cond->type      = type;
-    cond->negate    = negated;
+    cond->negate    = !!negated;
     cond->ref_count = 1;
 
     return cond;
@@ -495,7 +495,8 @@ libbalsa_condition_compare(LibBalsaCondition *c1,LibBalsaCondition *c2)
     if (c1 == c2) 
         return TRUE;
 
-    if (c1 == NULL || c2 == NULL || c1->type != c2->type)
+    if (c1 == NULL || c2 == NULL
+        || c1->type != c2->type || c1->negate != c2->negate)
         return FALSE;
 
     switch (c1->type) {
@@ -515,11 +516,14 @@ libbalsa_condition_compare(LibBalsaCondition *c1,LibBalsaCondition *c2)
                c1->match.date.date_high == c2->match.date.date_high);
         break;
     case CONDITION_FLAG:
-        res = (c2->type == CONDITION_FLAG &&
-               c1->match.flags == c2->match.flags);
+        res = (c1->match.flags == c2->match.flags);
         break;
     case CONDITION_AND:
     case CONDITION_OR:
+        /* We could declare c1 and c2 equal if (c1->left == c2->right)
+         * && (c1->right == c2->left), but we don't; the boolean value
+         * would be the same, but c1 and c2 could have different side
+         * effects. */
         res = (libbalsa_condition_compare(c1->match.andor.left,
                                           c2->match.andor.left) &&
                libbalsa_condition_compare(c1->match.andor.right,



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