Skip to content

Commit ec30a3b

Browse files
committed
Include stddef.h in zend_portability.h for offsetof() macro
This makes sure that we use compiler builtins when they are available and thus avoid ubsan warnings in clang. And also reindent the fallback implementation.
1 parent 4226c82 commit ec30a3b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

Zend/zend_portability.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#endif
5656

5757
#include <stdarg.h>
58+
#include <stddef.h>
5859

5960
#ifdef HAVE_DLFCN_H
6061
# include <dlfcn.h>
@@ -327,24 +328,19 @@ char *alloca();
327328

328329
#ifndef XtOffsetOf
329330
# if defined(CRAY) || (defined(__ARMCC_VERSION) && !defined(LINUX))
330-
# ifdef __STDC__
331-
# define XtOffset(p_type, field) _Offsetof(p_type, field)
332-
# else
333-
# ifdef CRAY2
334-
# define XtOffset(p_type, field) \
335-
(sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
336-
337-
# else /* !CRAY2 */
338-
339-
# define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
340-
341-
# endif /* !CRAY2 */
342-
# endif /* __STDC__ */
331+
# ifdef __STDC__
332+
# define XtOffset(p_type, field) _Offsetof(p_type, field)
333+
# else
334+
# ifdef CRAY2
335+
# define XtOffset(p_type, field) \
336+
(sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
337+
# else /* !CRAY2 */
338+
# define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
339+
# endif /* !CRAY2 */
340+
# endif /* __STDC__ */
343341
# else /* ! (CRAY || __arm) */
344-
345-
# define XtOffset(p_type, field) \
346-
((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
347-
342+
# define XtOffset(p_type, field) \
343+
((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
348344
# endif /* !CRAY */
349345

350346
# ifdef offsetof

0 commit comments

Comments
 (0)