From 87021209b3b190546f1da18f63175ccaa629cdbd Mon Sep 17 00:00:00 2001 From: eshifri <46511024+eshifri@users.noreply.github.com> Date: Wed, 4 May 2022 01:15:24 -0700 Subject: [PATCH] fix(colorlcd): EM crash when clearing Model Category name (#1897) (#1925) * Merge branch 'main' into eshifri/preserve_current_rebase * Initialize category name to zero. Without it KEY_ENTER adds garbage. --- radio/src/gui/colorlcd/model_select.cpp | 5 ++--- radio/src/storage/modelslist.cpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index a0bfa4abd..f35b1f104 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -740,7 +740,6 @@ class CategoryEditPage : public PageTab category->name[0] = ' '; category->name[1] = '\0'; } modelslist.save(); - update(); }); // Details @@ -749,7 +748,7 @@ class CategoryEditPage : public PageTab new StaticText(window, grid.getFieldSlot(3,1), cnt); if(category->empty()) { - new TextButton(window, grid.getFieldSlot(3,2),TR_DELETE, [=]() -> uint8_t { + new TextButton(window, grid.getFieldSlot(3,2),STR_DELETE, [=]() -> uint8_t { new ConfirmDialog(window, STR_DELETE_CATEGORY, std::string(category->name, sizeof(category->name)).c_str(), [=] { @@ -762,7 +761,7 @@ class CategoryEditPage : public PageTab } else { #ifdef CATEGORIES_SHOW_DELETE_NON_EMPTY new TextButton(window, grid.getFieldSlot(3,2),STR_DELETE, [=]() -> uint8_t { - new MessageDialog(window, STR_DELETE_CATEGORY, TR_CAT_NOT_EMPTY); + new MessageDialog(window, STR_DELETE_CATEGORY, STR_CAT_NOT_EMPTY); return 0; }); #endif diff --git a/radio/src/storage/modelslist.cpp b/radio/src/storage/modelslist.cpp index 0b28c932a..1d07a779d 100644 --- a/radio/src/storage/modelslist.cpp +++ b/radio/src/storage/modelslist.cpp @@ -187,6 +187,7 @@ bool ModelCell::fetchRfData() ModelsCategory::ModelsCategory(const char * name) { + memset(this->name, 0, sizeof(this->name)); strncpy(this->name, name, sizeof(this->name)); } @@ -194,7 +195,8 @@ ModelsCategory::ModelsCategory(const char * name, uint8_t len) { if (len > sizeof(this->name)-1) len = sizeof(this->name)-1; - + + memset(this->name, 0, sizeof(this->name)); memcpy(this->name, name, len); this->name[len] = '\0'; }