Fix undefined NULL pointer arithmetic in hlist
[urcu.git] / urcu / hlist.h
index 9f4332ac87d9afd33e48e5de6dcd3c4a96d5da88..462f4937363fa0c137ae8603531ec23399ec7d10 100644 (file)
@@ -93,14 +93,18 @@ void cds_hlist_del(struct cds_hlist_node *elem)
                        entry = cds_hlist_entry(pos, __typeof__(*entry), member))
 
 #define cds_hlist_for_each_entry_2(entry, head, member) \
-       for (entry = cds_hlist_entry((head)->next, __typeof__(*entry), member); \
-               &entry->member != NULL; \
-               entry = cds_hlist_entry(entry->member.next, __typeof__(*entry), member))
+       for (entry = ((head)->next == NULL ? NULL \
+                       : cds_hlist_entry((head)->next, __typeof__(*entry), member)); \
+               entry != NULL; \
+               entry = (entry->member.next == NULL ? NULL \
+                       : cds_hlist_entry(entry->member.next, __typeof__(*entry), member)))
 
 #define cds_hlist_for_each_entry_safe_2(entry, e, head, member) \
-       for (entry = cds_hlist_entry((head)->next, __typeof__(*entry), member); \
-               (&entry->member != NULL) && (e = cds_hlist_entry(entry->member.next, \
-                                               __typeof__(*entry), member), 1); \
+       for (entry = ((head)->next == NULL ? NULL \
+                       : cds_hlist_entry((head)->next, __typeof__(*entry), member)); \
+               (entry != NULL) && (e = (entry->member.next == NULL ? NULL \
+                                       : cds_hlist_entry(entry->member.next, \
+                                               __typeof__(*entry), member), 1)); \
                entry = e)
 
 #endif /* _KCOMPAT_HLIST_H */
This page took 0.030666 seconds and 4 git commands to generate.