aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lib/queue.h
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-03-31 19:22:11 -0400
committerGitHub <noreply@github.com>2021-03-31 19:22:11 -0400
commita177820420d3de1614bff01321c0a54a2327fab3 (patch)
tree54a2ea52ae7ca218f96416ba1ebebd09f10063ba /src/nvim/lib/queue.h
parentd55a69168f0ede6021ffe43dd8c059a350502dbc (diff)
parent5e4fb9a7dd9392cc59ab6b4f03a9f266c048b86c (diff)
downloadrneovim-a177820420d3de1614bff01321c0a54a2327fab3.tar.gz
rneovim-a177820420d3de1614bff01321c0a54a2327fab3.tar.bz2
rneovim-a177820420d3de1614bff01321c0a54a2327fab3.zip
Merge pull request #14259 from janlazo/fix-dictwatcherdel-crash
Fix dictwatcherdel crash
Diffstat (limited to 'src/nvim/lib/queue.h')
-rw-r--r--src/nvim/lib/queue.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/nvim/lib/queue.h b/src/nvim/lib/queue.h
index ab9270081e..452998a5a4 100644
--- a/src/nvim/lib/queue.h
+++ b/src/nvim/lib/queue.h
@@ -33,11 +33,17 @@ typedef struct _queue {
#define QUEUE_DATA(ptr, type, field) \
((type *)((char *)(ptr) - offsetof(type, field)))
-// Important note: mutating the list while QUEUE_FOREACH is
-// iterating over its elements results in undefined behavior.
-#define QUEUE_FOREACH(q, h) \
- for ( /* NOLINT(readability/braces) */ \
- (q) = (h)->next; (q) != (h); (q) = (q)->next)
+// Important note: the node currently being processed can be safely deleted.
+// otherwise, mutating the list while QUEUE_FOREACH is iterating over its
+// elements results in undefined behavior.
+#define QUEUE_FOREACH(q, h, code) \
+ (q) = (h)->next; \
+ while((q) != (h)) { \
+ QUEUE *next = q->next; \
+ code \
+ (q) = next; \
+ }
+
// ffi.cdef is unable to swallow `bool` in place of `int` here.
static inline int QUEUE_EMPTY(const QUEUE *const q)