chore(color): Use strAppend and strncmp on widgetName to avoid termination issues (#3905)
Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
@@ -96,12 +96,12 @@ void TopbarImpl::removeWidget(unsigned int index)
|
||||
bool mark = false;
|
||||
|
||||
// If user manually removes 'system' widgets, mark name so widget does not get reloaded on restart
|
||||
if ((index == MAX_TOPBAR_ZONES - 1) && (strcmp(persistentData->zones[index].widgetName, "Date Time") == 0))
|
||||
if ((index == MAX_TOPBAR_ZONES - 1) && (strncmp(persistentData->zones[index].widgetName, "Date Time", WIDGET_NAME_LEN) == 0))
|
||||
mark = true;
|
||||
if ((index == MAX_TOPBAR_ZONES - 2) && (strcmp(persistentData->zones[index].widgetName, "Radio Info") == 0))
|
||||
if ((index == MAX_TOPBAR_ZONES - 2) && (strncmp(persistentData->zones[index].widgetName, "Radio Info", WIDGET_NAME_LEN) == 0))
|
||||
mark = true;
|
||||
#if defined(INTERNAL_GPS)
|
||||
if ((index == MAX_TOPBAR_ZONES - 3) && (strcmp(persistentData->zones[index].widgetName, "Internal GPS") == 0))
|
||||
if ((index == MAX_TOPBAR_ZONES - 3) && (strncmp(persistentData->zones[index].widgetName, "Internal GPS", WIDGET_NAME_LEN) == 0))
|
||||
mark = true;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "widget.h"
|
||||
#include "widgets_container.h"
|
||||
#include "draw_functions.h"
|
||||
#include "strhelpers.h"
|
||||
|
||||
template <int N, int O>
|
||||
class WidgetsContainerImpl : public WidgetsContainer
|
||||
@@ -48,8 +49,7 @@ class WidgetsContainerImpl : public WidgetsContainer
|
||||
|
||||
Widget* widget = nullptr;
|
||||
if (factory) {
|
||||
strncpy(persistentData->zones[index].widgetName, factory->getName(),
|
||||
sizeof(ZonePersistentData::widgetName));
|
||||
strAppend(persistentData->zones[index].widgetName, factory->getName(), WIDGET_NAME_LEN);
|
||||
widget = factory->create(this, getZone(index),
|
||||
&persistentData->zones[index].widgetData);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class WidgetsContainerImpl : public WidgetsContainer
|
||||
if (persistentData->zones[i].widgetName[0]) {
|
||||
char name[WIDGET_NAME_LEN + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, persistentData->zones[i].widgetName, WIDGET_NAME_LEN);
|
||||
strAppend(name, persistentData->zones[i].widgetName, WIDGET_NAME_LEN);
|
||||
widgets[i] = loadWidget(name, this, getZone(i),
|
||||
&persistentData->zones[i].widgetData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user