Skip to content

Commit

Permalink
Assert "length > 0" for Meter.getUiName functions
Browse files Browse the repository at this point in the history
Because xSnprintf() will crash if the buffer size specified is zero.
  • Loading branch information
BenBE committed Aug 13, 2024
1 parent bb7a922 commit 480aefd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void CPUMeter_init(Meter* this) {

// Custom uiName runtime logic to include the param (processor)
static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) {
assert(length > 0);

if (this->param > 0)
xSnprintf(buffer, length, "%s %u", Meter_uiName(this), this->param);
else
Expand Down
3 changes: 3 additions & 0 deletions DynamicMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.

#include "DynamicMeter.h"

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -97,6 +98,8 @@ static const char* DynamicMeter_getCaption(const Meter* this) {
}

static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length) {
assert(length > 0);

const Settings* settings = this->host->settings;
const DynamicMeter* meter = Hashtable_get(settings->dynamicMeters, this->param);
if (meter) {
Expand Down

0 comments on commit 480aefd

Please sign in to comment.