diff --git a/libgnucash/engine/qofquery.cpp b/libgnucash/engine/qofquery.cpp index c17261896d..22793bf43a 100644 --- a/libgnucash/engine/qofquery.cpp +++ b/libgnucash/engine/qofquery.cpp @@ -1458,23 +1458,26 @@ gboolean qof_query_equal (const QofQuery *q1, const QofQuery *q2) if (q1 == q2) return TRUE; if (!q1 || !q2) return FALSE; - if (g_list_length (q1->terms) != g_list_length (q2->terms)) return FALSE; if (q1->max_results != q2->max_results) return FALSE; - for (or1 = q1->terms, or2 = q2->terms; or1; - or1 = or1->next, or2 = or2->next) + for (or1 = q1->terms, or2 = q2->terms; or1 || or2; + or1 = or1->next, or2 = or2->next) { GList *and1, *and2; + if (!or1 || !or2) + return FALSE; and1 = static_cast(or1->data); and2 = static_cast(or2->data); - if (g_list_length (and1) != g_list_length (and2)) return FALSE; - - for ( ; and1; and1 = and1->next, and2 = and2->next) + for (; and1 || and2; and1 = and1->next, and2 = and2->next) + { + if (!and1 || !and2) + return FALSE; if (!qof_query_term_equal (static_cast(and1->data), static_cast(and2->data))) return FALSE; + } } if (!qof_query_sort_equal (&(q1->primary_sort), &(q2->primary_sort))) diff --git a/libgnucash/engine/qofquerycore.cpp b/libgnucash/engine/qofquerycore.cpp index f9c8b980dd..51c5301135 100644 --- a/libgnucash/engine/qofquerycore.cpp +++ b/libgnucash/engine/qofquerycore.cpp @@ -732,9 +732,10 @@ guid_predicate_equal (const QofQueryPredData *p1, const QofQueryPredData *p2) GList *l1 = pd1->guids, *l2 = pd2->guids; if (pd1->options != pd2->options) return FALSE; - if (g_list_length (l1) != g_list_length (l2)) return FALSE; - for ( ; l1 ; l1 = l1->next, l2 = l2->next) + for (; l1 || l2; l1 = l1->next, l2 = l2->next) { + if (!l1 || !l2) + return FALSE; if (!guid_equal (static_cast(l1->data), static_cast(l2->data))) return FALSE; @@ -1525,9 +1526,10 @@ choice_predicate_equal (const QofQueryPredData *p1, const QofQueryPredData *p2) GList *l1 = pd1->guids, *l2 = pd2->guids; if (pd1->options != pd2->options) return FALSE; - if (g_list_length (l1) != g_list_length (l2)) return FALSE; - for ( ; l1 ; l1 = l1->next, l2 = l2->next) + for (; l1 || l2; l1 = l1->next, l2 = l2->next) { + if (!l1 || !l2) + return FALSE; if (!guid_equal (static_cast(l1->data), static_cast(l2->data))) return FALSE;