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.
This commit is contained in:
eshifri
2022-05-04 18:15:24 +10:00
committed by GitHub
parent b9d9f61456
commit 87021209b3
2 changed files with 5 additions and 4 deletions
+2 -3
View File
@@ -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
+3 -1
View File
@@ -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';
}