Include stddef.h in zend_portability.h for offsetof() macro
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 13 Sep 2019 19:52:17 +0000 (21:52 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 13 Sep 2019 22:24:47 +0000 (00:24 +0200)
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.

Zend/zend_portability.h

index 978f25bbfb8701f8cf21232d9437488a9fc0ab7a..1e549d300be84e68636b516b0fff5f704702a7d6 100644 (file)
@@ -55,6 +55,7 @@
 #endif
 
 #include <stdarg.h>
+#include <stddef.h>
 
 #ifdef HAVE_DLFCN_H
 # include <dlfcn.h>
@@ -327,24 +328,19 @@ char *alloca();
 
 #ifndef XtOffsetOf
 # if defined(CRAY) || (defined(__ARMCC_VERSION) && !defined(LINUX))
-# ifdef __STDC__
-# define XtOffset(p_type, field) _Offsetof(p_type, field)
-# else
-# ifdef CRAY2
-# define XtOffset(p_type, field) \
-    (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
-
-# else /* !CRAY2 */
-
-# define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
-
-# endif /* !CRAY2 */
-# endif /* __STDC__ */
+#  ifdef __STDC__
+#   define XtOffset(p_type, field) _Offsetof(p_type, field)
+#  else
+#   ifdef CRAY2
+#    define XtOffset(p_type, field) \
+       (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
+#   else /* !CRAY2 */
+#    define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
+#   endif /* !CRAY2 */
+#  endif /* __STDC__ */
 # else /* ! (CRAY || __arm) */
-
-# define XtOffset(p_type, field) \
-    ((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
-
+#  define XtOffset(p_type, field) \
+     ((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
 # endif /* !CRAY */
 
 # ifdef offsetof