Skip to content

Commit

Permalink
Use size_t as len type for Meter_UpdateValues
Browse files Browse the repository at this point in the history
Most of the time the parameter is passed to snprintf type functions
  • Loading branch information
cgzones authored and BenBE committed Dec 6, 2020
1 parent d9224c6 commit e1ce141
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion BatteryMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const int BatteryMeter_attributes[] = {
BATTERY
};

static void BatteryMeter_updateValues(Meter* this, char* buffer, int len) {
static void BatteryMeter_updateValues(Meter* this, char* buffer, size_t len) {
ACPresence isOnAC;
double percent;

Expand Down
2 changes: 1 addition & 1 deletion CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void CPUMeter_init(Meter* this) {
Meter_setCaption(this, "Avg");
}

static void CPUMeter_updateValues(Meter* this, char* buffer, int size) {
static void CPUMeter_updateValues(Meter* this, char* buffer, size_t size) {
int cpu = this->param;
if (cpu > this->pl->cpuCount) {
xSnprintf(buffer, size, "absent");
Expand Down
2 changes: 1 addition & 1 deletion ClockMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int ClockMeter_attributes[] = {
CLOCK
};

static void ClockMeter_updateValues(Meter* this, char* buffer, int size) {
static void ClockMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
Expand Down
2 changes: 1 addition & 1 deletion DateMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int DateMeter_attributes[] = {
DATE
};

static void DateMeter_updateValues(Meter* this, char* buffer, int size) {
static void DateMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
Expand Down
2 changes: 1 addition & 1 deletion DateTimeMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int DateTimeMeter_attributes[] = {
DATETIME
};

static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) {
static void DateTimeMeter_updateValues(Meter* this, char* buffer, size_t size) {
time_t t = time(NULL);
struct tm result;
struct tm* lt = localtime_r(&t, &result);
Expand Down
2 changes: 1 addition & 1 deletion DiskIOMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static unsigned long int cached_read_diff = 0;
static unsigned long int cached_write_diff = 0;
static double cached_utilisation_diff = 0.0;

static void DiskIOMeter_updateValues(Meter* this, char* buffer, int len) {
static void DiskIOMeter_updateValues(Meter* this, char* buffer, size_t len) {
static unsigned long long int cached_last_update = 0;

struct timeval tv;
Expand Down
2 changes: 1 addition & 1 deletion HostnameMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int HostnameMeter_attributes[] = {
HOSTNAME
};

static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) {
static void HostnameMeter_updateValues(Meter* this, char* buffer, size_t size) {
(void) this;
gethostname(buffer, size - 1);
}
Expand Down
4 changes: 2 additions & 2 deletions LoadAverageMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static const int LoadMeter_attributes[] = {
LOAD
};

static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, size_t size) {
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
}
Expand All @@ -40,7 +40,7 @@ static void LoadAverageMeter_display(const Object* cast, RichString* out) {
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
}

static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
static void LoadMeter_updateValues(Meter* this, char* buffer, size_t size) {
double five, fifteen;
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) {
Expand Down
2 changes: 1 addition & 1 deletion MemoryMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int MemoryMeter_attributes[] = {
MEMORY_CACHE
};

static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) {
static void MemoryMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written;
Platform_setMemoryValues(this);

Expand Down
5 changes: 2 additions & 3 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ
return this;
}

int Meter_humanUnit(char* buffer, unsigned long int value, int size) {
int Meter_humanUnit(char* buffer, unsigned long int value, size_t size) {
const char* prefix = "KMGTPEZY";
unsigned long int powi = 1;
unsigned int powj = 1, precision = 2;
Expand Down Expand Up @@ -441,8 +441,7 @@ const MeterMode* const Meter_modes[] = {

/* Blank meter */

static void BlankMeter_updateValues(Meter* this, char* buffer, int size) {
(void) this; (void) buffer; (void) size;
static void BlankMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) {
if (size > 0) {
*buffer = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct Meter_ Meter;
typedef void(*Meter_Init)(Meter*);
typedef void(*Meter_Done)(Meter*);
typedef void(*Meter_UpdateMode)(Meter*, int);
typedef void(*Meter_UpdateValues)(Meter*, char*, int);
typedef void(*Meter_UpdateValues)(Meter*, char*, size_t);
typedef void(*Meter_Draw)(Meter*, int, int, int);

typedef struct MeterClass_ {
Expand Down Expand Up @@ -101,7 +101,7 @@ extern const MeterClass Meter_class;

Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type);

int Meter_humanUnit(char* buffer, unsigned long int value, int size);
int Meter_humanUnit(char* buffer, unsigned long int value, size_t size);

void Meter_delete(Object* cast);

Expand Down
2 changes: 1 addition & 1 deletion NetworkIOMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static unsigned long int cached_rxp_diff = 0;
static unsigned long int cached_txb_diff = 0;
static unsigned long int cached_txp_diff = 0;

static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int len) {
static void NetworkIOMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t len) {
static unsigned long long int cached_last_update = 0;

struct timeval tv;
Expand Down
2 changes: 1 addition & 1 deletion SwapMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const int SwapMeter_attributes[] = {
SWAP
};

static void SwapMeter_updateValues(Meter* this, char* buffer, int size) {
static void SwapMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written;
Platform_setSwapValues(this);

Expand Down
2 changes: 1 addition & 1 deletion TasksMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static const int TasksMeter_attributes[] = {
TASKS_RUNNING
};

static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
static void TasksMeter_updateValues(Meter* this, char* buffer, size_t len) {
const ProcessList* pl = this->pl;
this->values[0] = pl->kernelThreads;
this->values[1] = pl->userlandThreads;
Expand Down
2 changes: 1 addition & 1 deletion UptimeMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const int UptimeMeter_attributes[] = {
UPTIME
};

static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) {
static void UptimeMeter_updateValues(Meter* this, char* buffer, size_t len) {
int totalseconds = Platform_getUptime();
if (totalseconds == -1) {
xSnprintf(buffer, len, "(unknown)");
Expand Down
2 changes: 1 addition & 1 deletion linux/PressureStallMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const int PressureStallMeter_attributes[] = {
PRESSURE_STALL_THREEHUNDRED
};

static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
static void PressureStallMeter_updateValues(Meter* this, char* buffer, size_t len) {
const char* file;
if (strstr(Meter_name(this), "CPU")) {
file = "cpu";
Expand Down
2 changes: 1 addition & 1 deletion linux/SELinuxMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static bool isSelinuxEnforcing(void) {
return !!enforce;
}

static void SELinuxMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int len) {
static void SELinuxMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t len) {
enabled = isSelinuxEnabled();
enforcing = isSelinuxEnforcing();

Expand Down
2 changes: 1 addition & 1 deletion linux/SystemdMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static void updateViaExec(void) {
fclose(commandOutput);
}

static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, int size) {
static void SystemdMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) {
free(systemState);
systemState = NULL;
nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE;
Expand Down
14 changes: 9 additions & 5 deletions linux/ZramMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const int ZramMeter_attributes[] = {
ZRAM
};

static void ZramMeter_updateValues(Meter* this, char* buffer, int size) {
static void ZramMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written;

Platform_setZramValues(this);
Expand All @@ -38,11 +38,15 @@ static void ZramMeter_updateValues(Meter* this, char* buffer, int size) {
}
*buffer++ = ')';
size--;
if ((size -= written) > 0) {
*buffer++ = '/';
size--;
Meter_humanUnit(buffer, this->total, size);
if (size <= 0) {
return;
}
*buffer++ = '/';
size--;
if (size <= 0) {
return;
}
Meter_humanUnit(buffer, this->total, size);
}

static void ZramMeter_display(const Object* cast, RichString* out) {
Expand Down
2 changes: 1 addition & 1 deletion zfs/ZfsArcMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
this->values[5] = stats->size;
}

static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
static void ZfsArcMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written;
Platform_setZfsArcValues(this);

Expand Down
4 changes: 2 additions & 2 deletions zfs/ZfsCompressedArcMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
}
}

static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) {
static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, size_t size) {
xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]);
}

static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int size) {
static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, size_t size) {
Platform_setZfsCompressedArcValues(this);

ZfsCompressedArcMeter_printRatioString(this, buffer, size);
Expand Down

0 comments on commit e1ce141

Please sign in to comment.