diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-24 15:47:20 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-24 19:34:25 +0900 |
commit | 61289d940597efb76bd7bcdd0501801733d9c9dd (patch) | |
tree | be05c9c4e47477e247399f25e242f6b58aeb5deb /ccan | |
parent | 86893b28f7ac7cc522d628577564d49a8f558d70 (diff) |
Initialize loop variable of `ccan_list_for_each`
On platforms where `typeof` is unsupported, `ccan_container_off_var`
calculates the offset of member by pointer subtraction. Although this
will result in the compile-time invariant value regardless the pointer
value, the loop variable will be used before assignment and may cause
an using uninitialized variable warning.
Diffstat (limited to 'ccan')
-rw-r--r-- | ccan/list/list.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ccan/list/list.h b/ccan/list/list.h index 30b2af04e9..bf692a6937 100644 --- a/ccan/list/list.h +++ b/ccan/list/list.h @@ -635,14 +635,16 @@ static inline void ccan_list_prepend_list_(struct ccan_list_head *to, /* internal macros, do not use directly */ #define ccan_list_for_each_off_dir_(h, i, off, dir) \ - for (i = ccan_list_node_to_off_(ccan_list_debug(h, CCAN_LIST_LOC)->n.dir, \ + for (i = 0, \ + i = ccan_list_node_to_off_(ccan_list_debug(h, CCAN_LIST_LOC)->n.dir, \ (off)); \ ccan_list_node_from_off_((void *)i, (off)) != &(h)->n; \ i = ccan_list_node_to_off_(ccan_list_node_from_off_((void *)i, (off))->dir, \ (off))) #define ccan_list_for_each_safe_off_dir_(h, i, nxt, off, dir) \ - for (i = ccan_list_node_to_off_(ccan_list_debug(h, CCAN_LIST_LOC)->n.dir, \ + for (i = 0, \ + i = ccan_list_node_to_off_(ccan_list_debug(h, CCAN_LIST_LOC)->n.dir, \ (off)), \ nxt = ccan_list_node_to_off_(ccan_list_node_from_off_(i, (off))->dir, \ (off)); \ |