[PATCH xserver v2] Fix uninitialized variable warnings reported by clang

Adam Jackson ajax at redhat.com
Tue Jan 5 09:51:41 PST 2016


From: Thomas Klausner <wiz at NetBSD.org>

v2: Move initializing pos into the first clause of the for statement. We
have to keep this macro equivalent to a plain for statement from the
user's perspective, otherwise callers need to {} things to keep control
flow correct. [ajax]

Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
Acked-by: Michel Dänzer <michel.daenzer at amd.com>
---
 include/list.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/list.h b/include/list.h
index 39f1985..3f0574d 100644
--- a/include/list.h
+++ b/include/list.h
@@ -304,8 +304,9 @@ xorg_list_is_empty(struct xorg_list *head)
  * @param member Member name of the struct xorg_list in the list elements.
  *
  */
-#define xorg_list_for_each_entry(pos, head, member)				\
-    for (pos = __container_of((head)->next, pos, member);		\
+#define xorg_list_for_each_entry(pos, head, member)			\
+    for (pos = NULL,                                                    \
+         pos = __container_of((head)->next, pos, member);		\
 	 &pos->member != (head);					\
 	 pos = __container_of(pos->member.next, pos, member))
 
@@ -317,7 +318,8 @@ xorg_list_is_empty(struct xorg_list *head)
  * See xorg_list_for_each_entry for more details.
  */
 #define xorg_list_for_each_entry_safe(pos, tmp, head, member)		\
-    for (pos = __container_of((head)->next, pos, member),		\
+    for (pos = NULL,                                                    \
+         pos = __container_of((head)->next, pos, member),		\
 	 tmp = __container_of(pos->member.next, pos, member);		\
 	 &pos->member != (head);					\
 	 pos = tmp, tmp = __container_of(pos->member.next, tmp, member))
-- 
2.5.0



More information about the xorg-devel mailing list