Replace list.h undefined behavior with offsetof.

master
AliceLR 5 years ago committed by Ozkan Sezer
parent 030907d14b
commit d741e61abd
  1. 6
      src/list.h

@ -4,6 +4,8 @@
#ifndef __LINUX_LIST_H #ifndef __LINUX_LIST_H
#define __LINUX_LIST_H #define __LINUX_LIST_H
#include <stddef.h> /* offsetof */
#ifdef _MSC_VER #ifdef _MSC_VER
#define __inline__ __inline #define __inline__ __inline
#endif #endif
@ -35,7 +37,7 @@ struct list_head {
} while (0) } while (0)
/* /*
* Insert a new entry between two known consecutive entries. * Insert a new entry between two known consecutive entries.
* *
* This is only for internal list manipulation where we know * This is only for internal list manipulation where we know
* the prev/next entries already! * the prev/next entries already!
@ -136,7 +138,7 @@ static __inline__ void list_splice(struct list_head *list, struct list_head *hea
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_entry(ptr, type, member) \ #define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) ((type *)((char *)(ptr) - offsetof(type, member)))
/** /**
* list_for_each - iterate over a list * list_for_each - iterate over a list

Loading…
Cancel
Save