fix wrong operator precedence in destructor macros

Sun, 09 Apr 2023 20:00:44 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 09 Apr 2023 20:00:44 +0200
changeset 680
19379743e5a0
parent 679
022fbd4bc057
child 681
502105523db7

fix wrong operator precedence in destructor macros

src/cx/collection.h file | annotate | diff | comparison | revisions
src/list.c file | annotate | diff | comparison | revisions
tests/test_list.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/cx/collection.h	Sun Apr 09 19:37:00 2023 +0200
     1.2 +++ b/src/cx/collection.h	Sun Apr 09 20:00:44 2023 +0200
     1.3 @@ -112,7 +112,7 @@
     1.4   * @param e the element
     1.5   */
     1.6  #define cx_invoke_simple_destructor(c, e) \
     1.7 -    (c)->simple_destructor((c)->store_pointer ? (*((void **) e)) : e)
     1.8 +    (c)->simple_destructor((c)->store_pointer ? (*((void **) (e))) : (e))
     1.9  
    1.10  /**
    1.11   * Invokes the advanced destructor function for a specific element.
    1.12 @@ -125,7 +125,7 @@
    1.13   */
    1.14  #define cx_invoke_advanced_destructor(c, e) \
    1.15      (c)->advanced_destructor((c)->destructor_data, \
    1.16 -    (c)->store_pointer ? (*((void **) e)) : e)
    1.17 +    (c)->store_pointer ? (*((void **) (e))) : (e))
    1.18  
    1.19  
    1.20  #define cx_invoke_destructor(c, e) \
     2.1 --- a/src/list.c	Sun Apr 09 19:37:00 2023 +0200
     2.2 +++ b/src/list.c	Sun Apr 09 20:00:44 2023 +0200
     2.3 @@ -219,11 +219,11 @@
     2.4          CxList const *list,
     2.5          CxList const *other
     2.6  ) {
     2.7 -    if (list->cl->compare == other->cl->compare) {
     2.8 -        // same compare function, lists are compatible
     2.9 -        return list->cl->compare(list, other);
    2.10 -    } else {
    2.11 -        // different compare functions, use iterator
    2.12 +    if ((list->store_pointer ^ other->store_pointer) ||
    2.13 +        ((list->climpl == NULL) ^ (other->climpl != NULL)) ||
    2.14 +        ((list->climpl != NULL ? list->climpl->compare : list->cl->compare) !=
    2.15 +         (other->climpl != NULL ? other->climpl->compare : other->cl->compare))) {
    2.16 +        // lists are definitely different - cannot use internal compare function
    2.17          if (list->size == other->size) {
    2.18              CxIterator left = cxListIterator(list);
    2.19              CxIterator right = cxListIterator(other);
    2.20 @@ -241,6 +241,9 @@
    2.21          } else {
    2.22              return list->size < other->size ? -1 : 1;
    2.23          }
    2.24 +    } else {
    2.25 +        // lists are compatible
    2.26 +        return list->cl->compare(list, other);
    2.27      }
    2.28  }
    2.29  
     3.1 --- a/tests/test_list.cpp	Sun Apr 09 19:37:00 2023 +0200
     3.2 +++ b/tests/test_list.cpp	Sun Apr 09 20:00:44 2023 +0200
     3.3 @@ -751,8 +751,6 @@
     3.4          cxListClear(list);
     3.5          EXPECT_EQ(testdata_len, destr_test_ctr);
     3.6          EXPECT_EQ(testdata.data[testdata_len - 1], destr_last_value + off);
     3.7 -
     3.8 -
     3.9      }
    3.10  
    3.11      void verifySimpleDestructor(CxList *list) {

mercurial