Skip to content

Commit 480aefd

Browse files
committed
Assert "length > 0" for Meter.getUiName functions
Because xSnprintf() will crash if the buffer size specified is zero.
1 parent bb7a922 commit 480aefd

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

CPUMeter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static void CPUMeter_init(Meter* this) {
5555

5656
// Custom uiName runtime logic to include the param (processor)
5757
static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) {
58+
assert(length > 0);
59+
5860
if (this->param > 0)
5961
xSnprintf(buffer, length, "%s %u", Meter_uiName(this), this->param);
6062
else

DynamicMeter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ in the source distribution for its full text.
1010

1111
#include "DynamicMeter.h"
1212

13+
#include <assert.h>
1314
#include <stdbool.h>
1415
#include <stddef.h>
1516
#include <string.h>
@@ -97,6 +98,8 @@ static const char* DynamicMeter_getCaption(const Meter* this) {
9798
}
9899

99100
static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length) {
101+
assert(length > 0);
102+
100103
const Settings* settings = this->host->settings;
101104
const DynamicMeter* meter = Hashtable_get(settings->dynamicMeters, this->param);
102105
if (meter) {

0 commit comments

Comments
 (0)