tree.h cache-instrumented macros were invalidating NULL pointers in some cases
[keystone-rtos/rm-lld.git] / util / tree.h
index 8ada42d2f9c1082b1676b652a9d9233583ef0fbf..c2713901ce45f38016945aa455b43fb6f0206a68 100644 (file)
@@ -719,31 +719,33 @@ name##_RB_MINMAX(struct name *head, int val)                              \
                        tmp = RB_RIGHT(tmp, field);                     \
        }                                                               \
        return (parent);                                                \
                        tmp = RB_RIGHT(tmp, field);                     \
        }                                                               \
        return (parent);                                                \
-}                                   \
-                                                                               \
+}                                                                                      \
+                                                                       \
 /* ARGSUSED */                                                         \
 attr struct type *                                                     \
 name##_RB_NEXT_CACHED(struct type *elm)                                        \
 {                                                                      \
 /* ARGSUSED */                                                         \
 attr struct type *                                                     \
 name##_RB_NEXT_CACHED(struct type *elm)                                        \
 {                                                                      \
-    inv(elm);                               \
+       inv(elm);                                                                       \
        if (RB_RIGHT(elm, field)) {                                     \
                elm = RB_RIGHT(elm, field);                             \
        if (RB_RIGHT(elm, field)) {                                     \
                elm = RB_RIGHT(elm, field);                             \
-               inv(elm);                               \
+               inv(elm);                                                               \
                while (RB_LEFT(elm, field)) {                           \
                        elm = RB_LEFT(elm, field);                      \
                while (RB_LEFT(elm, field)) {                           \
                        elm = RB_LEFT(elm, field);                      \
-                       inv(elm);                               \
-               }                                       \
+                       inv(elm);                                                       \
+               }                                                                               \
        } else {                                                        \
        } else {                                                        \
-           inv(RB_PARENT(elm, field));            \
+               if (RB_PARENT(elm, field))              \
+                       inv(RB_PARENT(elm, field));     \
                if (RB_PARENT(elm, field) &&                            \
                if (RB_PARENT(elm, field) &&                            \
-                   (elm == RB_LEFT(RB_PARENT(elm, field), field)))     \
+                       (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
                        elm = RB_PARENT(elm, field);                    \
                else {                                                  \
                        while (RB_PARENT(elm, field) &&                 \
                        elm = RB_PARENT(elm, field);                    \
                else {                                                  \
                        while (RB_PARENT(elm, field) &&                 \
-                           (elm == RB_RIGHT(RB_PARENT(elm, field), field))) {\
+                               (elm == RB_RIGHT(RB_PARENT(elm, field), field))) {\
                                elm = RB_PARENT(elm, field);            \
                                elm = RB_PARENT(elm, field);            \
-                               inv(RB_PARENT(elm, field));                      \
-                       }                                       \
+                               if (RB_PARENT(elm, field))                      \
+                                       inv(RB_PARENT(elm, field));             \
+                       }                                                                               \
                        elm = RB_PARENT(elm, field);                    \
                }                                                       \
        }                                                               \
                        elm = RB_PARENT(elm, field);                    \
                }                                                       \
        }                                                               \
@@ -756,8 +758,8 @@ name##_RB_MINMAX_CACHED(struct name *head, int val)                         \
        struct type *tmp = RB_ROOT(head);                               \
        struct type *parent = NULL;                                     \
        while (tmp) {                                                   \
        struct type *tmp = RB_ROOT(head);                               \
        struct type *parent = NULL;                                     \
        while (tmp) {                                                   \
+               inv(tmp);                                                       \
                parent = tmp;                                           \
                parent = tmp;                                           \
-               inv(tmp);                               \
                if (val < 0)                                            \
                        tmp = RB_LEFT(tmp, field);                      \
                else                                                    \
                if (val < 0)                                            \
                        tmp = RB_LEFT(tmp, field);                      \
                else                                                    \