[color] do not use setValue() in SourceChoice / SwitchChoice

This potentially deletes the source/switch choice, which then triggers a "use-after-free".

Resolves #759
This commit is contained in:
Raphael Coeffic
2021-09-20 11:04:11 +10:00
committed by Peter Feerick
parent 66b523cf88
commit 64a87812bb
6 changed files with 11 additions and 18 deletions
+1 -1
View File
@@ -345,7 +345,7 @@ class ModelCategoryPageBody : public FormWindow
#endif #endif
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) bool onTouchEnd(coord_t x, coord_t y) override
{ {
if(category->size() == 0) if(category->size() == 0)
addFirstModel(); addFirstModel();
+3 -9
View File
@@ -70,10 +70,7 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
menu->setWaitHandler([=]() { menu->setWaitHandler([=]() {
int16_t val = getMovedSource(vmin); int16_t val = getMovedSource(vmin);
if (val) { if (val) {
if (setValue) { fillMenu(menu, val);
setValue(val);
}
this->fillMenu(menu);
} }
#if defined(AUTOSWITCH) #if defined(AUTOSWITCH)
else { else {
@@ -81,8 +78,7 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) { if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
val = switchToMix(swtch); val = switchToMix(swtch);
if (val && (val >= vmin) && (val <= vmax)) { if (val && (val >= vmin) && (val <= vmax)) {
if (setValue) setValue(val); fillMenu(menu, val);
this->fillMenu(menu);
} }
} }
} }
@@ -101,10 +97,8 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
setAvailableHandler([](int v){ return isSourceAvailable(v); }); setAvailableHandler([](int v){ return isSourceAvailable(v); });
} }
void SourceChoice::fillMenu(Menu *menu, void SourceChoice::fillMenu(Menu *menu, int16_t value, const FilterFct& filter)
const std::function<bool(int16_t)> &filter)
{ {
auto value = getValue();
int count = 0; int count = 0;
int current = 0; int current = 0;
+2 -2
View File
@@ -42,8 +42,8 @@ class SourceChoice : public ChoiceEx
#endif #endif
protected: protected:
void fillMenu(Menu* menu, typedef std::function<bool(int16_t)> FilterFct;
const std::function<bool(int16_t)>& condition = nullptr); void fillMenu(Menu* menu, int16_t value, const FilterFct& condition = nullptr);
}; };
#endif // _SOURCECHOICE_H_ #endif // _SOURCECHOICE_H_
+2 -4
View File
@@ -62,8 +62,7 @@ SwitchChoice::SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin,
val = swtch; val = swtch;
} }
if (val && (!isValueAvailable || isValueAvailable(val))) { if (val && (!isValueAvailable || isValueAvailable(val))) {
if (setValue) setValue(val); fillMenu(menu, val);
this->fillMenu(menu);
} }
} }
}); });
@@ -88,9 +87,8 @@ SwitchChoice::SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin,
setAvailableHandler(isSwitchAvailableInMixes); setAvailableHandler(isSwitchAvailableInMixes);
} }
void SwitchChoice::fillMenu(Menu* menu, std::function<bool(int16_t)> filter) void SwitchChoice::fillMenu(Menu* menu, int16_t value, const FilterFct& filter)
{ {
auto value = getValue();
int count = 0; int count = 0;
int current = 0; int current = 0;
+2 -1
View File
@@ -38,7 +38,8 @@ class SwitchChoice : public ChoiceEx
#endif #endif
protected: protected:
void fillMenu(Menu* menu, std::function<bool(int16_t)> condition = nullptr); typedef std::function<bool(int16_t)> FilterFct;
void fillMenu(Menu* menu, int16_t value, const FilterFct& filter = nullptr);
}; };
#endif // _SWITCHCHOICE_H_ #endif // _SWITCHCHOICE_H_