Skip to content

Commit c48b180

Browse files
committed
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 ```
1 parent 9fb683a commit c48b180

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/nanobind/nb_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ template <typename... Args> struct init {
305305
if constexpr (!std::is_same_v<Type, Alias> &&
306306
std::is_constructible_v<Type, Args...>) {
307307
if (!detail::nb_inst_python_derived(v.h.ptr())) {
308-
new ((Type *) v.p) Type{ (detail::forward_t<Args>) args... };
308+
new (v.p) Type{ (detail::forward_t<Args>) args... };
309309
return;
310310
}
311311
}
312-
new ((Alias *) v.p) Alias{ (detail::forward_t<Args>) args... };
312+
new ((void *) v.p) Alias{ (detail::forward_t<Args>) args... };
313313
},
314314
extra...);
315315
}

0 commit comments

Comments
 (0)