Fix: False positives/negatives in curves_selection.cc#contains #116834

Merged
Hans Goudey merged 5 commits from Mysteryem/blender:fix_curves_selection_contains into main 2024-01-09 17:40:23 +01:00

5 Commits

Author SHA1 Message Date
Thomas Barlow 1a8e82dbf3 Use a variable for range.one_after_last() to simplify code
Make format.
2024-01-09 16:31:16 +00:00
Thomas Barlow 2108a6b619 Make format 2024-01-06 03:16:01 +00:00
Thomas Barlow fdd50f2b72 Fix: The search value is ignored in curves_selection.cc#contains
A couple of parts of the function always searched for `true` instead of
the `value` argument.

This may have gone unnoticed because the `contains` function is only
ever used to search for `true`.
2024-01-06 03:01:41 +00:00
Thomas Barlow bc9ad440ea Fix: Searching uninitialized `values` array in curves_selection.cc#contains
The `values` array has a fixed size of `MaxChunkSize`. When `size` is
smaller than `MaxChunkSize`, only the first `size` elements of `values`
will have been initialized by `varray.materialize_compressed`, but
`std::find` was searching through the entirety of `values` every time.

This could cause false positive results due to the uninitialized values
having a chance to match the value being searched for.
2024-01-06 03:01:41 +00:00
Thomas Barlow 171adbbbf7 Fix: off-by-1 in curves_selection.cc#contains
Consider an IndexRange of 8 elements starting at 0:
`range.start()` will be `0` and `range.last()` will be `7`.

The size of the range is not `range.last() - range.start()` because that
will be 7, but rather `range.one_after_last() - range.start()`.

The code was using `last()` when it should have been using
`one_after_last()`, which would cause the very last element of each
2048-element section (as per the grain size) of `varray` to be skipped.
2024-01-06 03:01:41 +00:00