Fix array index access at negative index

Conversion from negative float to unsigned is saturating to 0 in rust
and undefined behavior in C++, we should therefore handle the case
properly

Fixes #8222
This commit is contained in:
Olivier Goffart 2025-04-22 11:28:09 +02:00 committed by GitHub
parent ff6065ace4
commit cd8ab8ce53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 10 deletions

View file

@ -25,9 +25,9 @@ struct ModelChangeListener
using ModelPeer = std::weak_ptr<ModelChangeListener>;
template<typename M>
auto access_array_index(const std::shared_ptr<M> &model, size_t index)
auto access_array_index(const std::shared_ptr<M> &model, std::ptrdiff_t index)
{
if (!model) {
if (!model || index < 0) {
return decltype(*model->row_data_tracked(index)) {};
} else if (const auto v = model->row_data_tracked(index)) {
return *v;