fix(stl): determine the sequence length only once in array_caster (#6278)
* fix(stl): determine the sequence length only once in array_caster
The element loops of `array_caster` asked the sequence for its length
more than once: one time to size the storage, and again for the end of
the iteration. A sequence that reports different lengths could cause
out-of-bounds accesses (a write for `std::valarray`, a read for
`std::array`).
The loops now read the length one time and index up to it.
Assisted-by: ClaudeCode:claude-fable-5-2
* fix(stl): construct each element caster before its item is fetched
This keeps the order that the loops had when they iterated over the
sequence.
Assisted-by: ClaudeCode:claude-fable-5-2
3 files changed