Fix linear_gradient float precision bug.

This was reported by:
https://github.com/ArthurSonzogni/FTXUI/issues/998

Indeed, the `t` interpolation factor, which is itself interpolated might become
slightly larger than 1.0. This is due to the float precision.
This was supposedly handled, but there was an off-by-one error in the check.

Along the way, fix a bug found by a fuzzer.

Bug: https://github.com/ArthurSonzogni/FTXUI/issues/998
Fixed: https://github.com/ArthurSonzogni/FTXUI/issues/998
This commit is contained in:
Arthur Sonzogni
2025-02-10 22:51:31 +01:00
committed by ArthurSonzogni
parent 15587dad01
commit d75108e960
6 changed files with 48 additions and 6 deletions

View File

@@ -47,7 +47,11 @@ Component Dropdown(DropdownOption option) {
Element Render() override {
radiobox.selected =
util::clamp(radiobox.selected(), 0, int(radiobox.entries.size()) - 1);
title_ = radiobox.entries[selected_()];
selected_ = util::clamp(selected_(), 0, int(radiobox.entries.size()) - 1);
if (selected_() >= 0) {
title_ = radiobox.entries[selected_()];
}
return transform(*open_, checkbox_->Render(), radiobox_->Render());
}