Skip to content

Commit

Permalink
chore(color): Use strAppend and strncmp on widgetName to avoid termin…
Browse files Browse the repository at this point in the history
…ation issues (#3905)

Co-authored-by: Phil Mitchell <[email protected]>
  • Loading branch information
philmoz and Phil Mitchell authored Aug 5, 2023
1 parent 659a25a commit ac4aeef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions radio/src/gui/colorlcd/layouts/topbar_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/colorlcd/widgets/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions radio/src/storage/storage_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ void postModelLoad(bool alarms)
#if defined(COLORLCD)
// Load 'date time' widget if slot is empty
if (g_model.topbarData.zones[MAX_TOPBAR_ZONES-1].widgetName[0] == 0) {
strcpy(g_model.topbarData.zones[MAX_TOPBAR_ZONES-1].widgetName, "Date Time");
strAppend(g_model.topbarData.zones[MAX_TOPBAR_ZONES-1].widgetName, "Date Time", WIDGET_NAME_LEN);
g_model.topbarData.zones[MAX_TOPBAR_ZONES-1].widgetData.options[0].type = ZOV_Color;
g_model.topbarData.zones[MAX_TOPBAR_ZONES-1].widgetData.options[0].value.unsignedValue = 0xFFFFFF;
storageDirty(EE_MODEL);
}
// Load 'radio info' widget if slot is empty
if (g_model.topbarData.zones[MAX_TOPBAR_ZONES-2].widgetName[0] == 0) {
strcpy(g_model.topbarData.zones[MAX_TOPBAR_ZONES-2].widgetName, "Radio Info");
strAppend(g_model.topbarData.zones[MAX_TOPBAR_ZONES-2].widgetName, "Radio Info", WIDGET_NAME_LEN);
storageDirty(EE_MODEL);
}
#if defined(INTERNAL_GPS)
// Load 'internal gps' widget if slot is empty
if (g_model.topbarData.zones[MAX_TOPBAR_ZONES-3].widgetName[0] == 0) {
strcpy(g_model.topbarData.zones[MAX_TOPBAR_ZONES-3].widgetName, "Internal GPS");
strAppend(g_model.topbarData.zones[MAX_TOPBAR_ZONES-3].widgetName, "Internal GPS", WIDGET_NAME_LEN);
storageDirty(EE_MODEL);
}
#endif
Expand Down

0 comments on commit ac4aeef

Please sign in to comment.