Skip to content

Commit c89561f

Browse files
committed
Fix actual undefined behavior exposed by previous changes.
It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here: https://github.com/pybind/pybind11/blob/f3e0602802c7840992c97f4960515777cad6a5c7/include/pybind11/detail/type_caster_base.h#L262-L263 ``` 259 // Main constructor for a found value/holder: 260 value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index) 261 : inst{i}, index{index}, type{type}, 262 vh{inst->simple_layout ? inst->simple_value_holder 263 : &inst->nonsimple.values_and_holders[vpos]} {} ```
1 parent cf5958d commit c89561f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

include/pybind11/detail/type_caster_base.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,16 @@ struct values_and_holders {
349349
const type_vec *types = nullptr;
350350
value_and_holder curr;
351351
friend struct values_and_holders;
352-
iterator(instance *inst, const type_vec *tinfo)
353-
: inst{inst}, types{tinfo},
354-
curr(inst /* instance */,
355-
types->empty() ? nullptr : (*types)[0] /* type info */,
356-
0, /* vpos: (non-simple types only): the first vptr comes first */
357-
0 /* index */) {}
352+
iterator(instance *inst, const type_vec *tinfo) : inst{inst}, types{tinfo} {
353+
if (inst != nullptr) {
354+
assert(!types->empty());
355+
curr = value_and_holder(
356+
inst /* instance */,
357+
(*types)[0] /* type info */,
358+
0, /* vpos: (non-simple types only): the first vptr comes first */
359+
0 /* index */);
360+
}
361+
}
358362
// Past-the-end iterator:
359363
explicit iterator(size_t end) : curr(end) {}
360364

0 commit comments

Comments
 (0)