fix potential null pointer access

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 29fcc8d0fd
commit 502b37a19a
2 changed files with 18 additions and 14 deletions
+2
View File
@@ -29,11 +29,13 @@ void choicePaintCallback(lv_event_t *e)
lv_obj_t *target = lv_event_get_target(e); lv_obj_t *target = lv_event_get_target(e);
if (target != nullptr) { if (target != nullptr) {
ChoiceBase *cb = (ChoiceBase*)lv_obj_get_user_data(target); ChoiceBase *cb = (ChoiceBase*)lv_obj_get_user_data(target);
if (cb) {
std::string text = cb->getLabelText(); std::string text = cb->getLabelText();
lv_label_set_text(cb->label, text.c_str()); lv_label_set_text(cb->label, text.c_str());
} }
} }
} }
}
ChoiceBase::ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type, WindowFlags windowFlags): ChoiceBase::ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type, WindowFlags windowFlags):
FormField(parent, rect, windowFlags), FormField(parent, rect, windowFlags),
+2
View File
@@ -31,6 +31,7 @@ void menuBodyEventCallback(lv_event_t *e)
if (target != nullptr) { if (target != nullptr) {
long index = (long)lv_event_get_user_data(e); long index = (long)lv_event_get_user_data(e);
MenuBody *mb = (MenuBody *) lv_obj_get_user_data(lv_obj_get_parent(target)); MenuBody *mb = (MenuBody *) lv_obj_get_user_data(lv_obj_get_parent(target));
if (mb) {
Menu *menu = mb->getParentMenu(); Menu *menu = mb->getParentMenu();
if (index < (int)mb->lines.size()) { if (index < (int)mb->lines.size()) {
onKeyPress(); onKeyPress();
@@ -49,6 +50,7 @@ void menuBodyEventCallback(lv_event_t *e)
} }
} }
} }
}
MenuBody::MenuBody(Window * parent, const rect_t & rect): MenuBody::MenuBody(Window * parent, const rect_t & rect):
Window(parent, rect, OPAQUE, 0, lv_list_create) Window(parent, rect, OPAQUE, 0, lv_list_create)