Skip to content

Commit

Permalink
Fixed another sanitizer issue
Browse files Browse the repository at this point in the history
``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
```
  • Loading branch information
wjakob committed Aug 23, 2023
1 parent 9fb683a commit c48b180
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/nanobind/nb_class.h
Expand Up @@ -305,11 +305,11 @@ template <typename... Args> struct init {
if constexpr (!std::is_same_v<Type, Alias> &&
std::is_constructible_v<Type, Args...>) {
if (!detail::nb_inst_python_derived(v.h.ptr())) {
new ((Type *) v.p) Type{ (detail::forward_t<Args>) args... };
new (v.p) Type{ (detail::forward_t<Args>) args... };
return;
}
}
new ((Alias *) v.p) Alias{ (detail::forward_t<Args>) args... };
new ((void *) v.p) Alias{ (detail::forward_t<Args>) args... };
},
extra...);
}
Expand Down

0 comments on commit c48b180

Please sign in to comment.