From c48b180834b4929f2f77ce658f2a50ee78482fb7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 23 Aug 2023 09:22:54 +0200 Subject: [PATCH] Fixed another sanitizer issue ``tests/test_intrusive.py::test04_subclass`` produced the below error in the UB sanitizer. This is likely a fluke since the object in question is being initialized (via placement new), not read. That said, it is easy to suppress the warning, which is what this commit does. ``` /Users/wjakob/nanobind/include/nanobind/nb_class.h:312:22: runtime error: downcast of address 0x00010f167ed8 which does not point to an object of type 'Alias' (aka 'PyTest') 0x00010f167ed8: note: object has invalid vptr 43 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ invalid vptr SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/wjakob/nanobind/include/nanobind/nb_class.h:312:22 ``` --- include/nanobind/nb_class.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nanobind/nb_class.h b/include/nanobind/nb_class.h index 3f1801a2..1ab0e74b 100644 --- a/include/nanobind/nb_class.h +++ b/include/nanobind/nb_class.h @@ -305,11 +305,11 @@ template struct init { if constexpr (!std::is_same_v && std::is_constructible_v) { if (!detail::nb_inst_python_derived(v.h.ptr())) { - new ((Type *) v.p) Type{ (detail::forward_t) args... }; + new (v.p) Type{ (detail::forward_t) args... }; return; } } - new ((Alias *) v.p) Alias{ (detail::forward_t) args... }; + new ((void *) v.p) Alias{ (detail::forward_t) args... }; }, extra...); }