summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-07-25 19:55:21 +0200
committerJean-François Milants <jf@codingfield.com>2021-07-25 19:55:21 +0200
commit514481ef7f9c71ad816b31d979c6ab39ce9380dd (patch)
tree5035758f67041f22d273cb6a3384ec7777310804 /src/displayapp/screens
parent7b75ca591d31ccd8883a1a1ff83cfd271959dbaa (diff)
Tile event handler : read the event data only if the event is a "value changed event". LVGL sends many other event and some of them do not set the event data (global static variable) to a valid address, which may cause an invalid read. I noticed that when porting this class on RISC-V platform (BL602).
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/Tile.cpp18
-rw-r--r--src/displayapp/screens/Tile.h2
2 files changed, 11 insertions, 9 deletions
diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp
index 3eb127cc..d5d6cb80 100644
--- a/src/displayapp/screens/Tile.cpp
+++ b/src/displayapp/screens/Tile.cpp
@@ -6,15 +6,17 @@ using namespace Pinetime::Applications::Screens;
namespace {
static void lv_update_task(struct _lv_task_t* task) {
- auto user_data = static_cast<Tile*>(task->user_data);
+ auto* user_data = static_cast<Tile*>(task->user_data);
user_data->UpdateScreen();
}
static void event_handler(lv_obj_t* obj, lv_event_t event) {
+ if (event != LV_EVENT_VALUE_CHANGED) return;
+
Tile* screen = static_cast<Tile*>(obj->user_data);
- uint32_t* eventDataPtr = (uint32_t*) lv_event_get_data();
+ auto* eventDataPtr = (uint32_t*) lv_event_get_data();
uint32_t eventData = *eventDataPtr;
- screen->OnObjectEvent(obj, event, eventData);
+ screen->OnValueChangedEvent(obj, eventData);
}
}
@@ -124,9 +126,9 @@ bool Tile::Refresh() {
return running;
}
-void Tile::OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId) {
- if (event == LV_EVENT_VALUE_CHANGED) {
- app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
- running = false;
- }
+void Tile::OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId) {
+ if(obj != btnm1) return;
+
+ app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
+ running = false;
}
diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h
index 4ebd81cd..765a8def 100644
--- a/src/displayapp/screens/Tile.h
+++ b/src/displayapp/screens/Tile.h
@@ -32,7 +32,7 @@ namespace Pinetime {
bool Refresh() override;
void UpdateScreen();
- void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId);
+ void OnValueChangedEvent(lv_obj_t* obj, uint32_t buttonId);
private:
Pinetime::Controllers::Battery& batteryController;