[libunwind] [libunwind] Undefined behaviour pointer arithmetic with null pointer (PR #98648)
Daniel Kiss via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 12:03:58 PDT 2024
================
@@ -230,8 +230,13 @@ void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
}
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
-
-#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
+template <typename TYPE, typename FIELD>
+__attribute__((no_sanitize("undefined"))) static inline size_t
+_arrayoffsetof(int index, FIELD TYPE::*field) {
+ return ((size_t)(&(((TYPE *)0)[index].*field)));
+}
+#define arrayoffsetof(type, index, field) \
+ _arrayoffsetof<struct type>(index, &type::field)
----------------
DanielKristofKiss wrote:
Correct (facepalm) no need for my overcomplicated code... Thanks!
https://github.com/llvm/llvm-project/pull/98648
More information about the cfe-commits
mailing list