Skip to content

Commit

Permalink
Improve DynamicMeter_getUiName() string length logic
Browse files Browse the repository at this point in the history
Use 'size_t' for 'uiName' length variable and use String_safeStrncpy()
for copying strings.

Using 'size_t' for string length prevents a "-Wshorten-64-to-32"
warning which is enabled by default in Clang 19.
  • Loading branch information
Explorer09 committed Aug 12, 2024
1 parent 9f32ea7 commit 032721c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions DynamicMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length)
if (meter) {
const char* uiName = meter->caption;
if (uiName) {
int len = strlen(uiName);
if (len > 2 && uiName[len - 2] == ':')
len -= 2;
xSnprintf(name, length, "%.*s", len, uiName);
size_t uiNameLen = strlen(uiName);
if (uiNameLen > 2 && uiName[uiNameLen - 2] == ':')
uiNameLen -= 2;

String_safeStrncpy(name, uiName, MINIMUM(length, uiNameLen + 1));
} else {
xSnprintf(name, length, "%s", meter->name);
String_safeStrncpy(name, meter->name, length);
}
}
}
Expand Down

0 comments on commit 032721c

Please sign in to comment.