Use size_t as len type for Meter_UpdateValues

Most of the time the parameter is passed to snprintf type functions
This commit is contained in:
Christian Göttsche 2020-11-24 18:31:03 +01:00 committed by Benny Baumann
parent d9224c66a4
commit e1ce141bc3
21 changed files with 33 additions and 30 deletions

View File

@ -21,7 +21,7 @@ static const int BatteryMeter_attributes[] = {
BATTERY BATTERY
}; };
static void BatteryMeter_updateValues(Meter* this, char* buffer, int len) { static void BatteryMeter_updateValues(Meter* this, char* buffer, size_t len) {
ACPresence isOnAC; ACPresence isOnAC;
double percent; double percent;

View File

@ -50,7 +50,7 @@ static void CPUMeter_init(Meter* this) {
Meter_setCaption(this, "Avg"); 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; int cpu = this->param;
if (cpu > this->pl->cpuCount) { if (cpu > this->pl->cpuCount) {
xSnprintf(buffer, size, "absent"); xSnprintf(buffer, size, "absent");

View File

@ -19,7 +19,7 @@ static const int ClockMeter_attributes[] = {
CLOCK 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); time_t t = time(NULL);
struct tm result; struct tm result;
struct tm* lt = localtime_r(&t, &result); struct tm* lt = localtime_r(&t, &result);

View File

@ -19,7 +19,7 @@ static const int DateMeter_attributes[] = {
DATE 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); time_t t = time(NULL);
struct tm result; struct tm result;
struct tm* lt = localtime_r(&t, &result); struct tm* lt = localtime_r(&t, &result);

View File

@ -19,7 +19,7 @@ static const int DateTimeMeter_attributes[] = {
DATETIME 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); time_t t = time(NULL);
struct tm result; struct tm result;
struct tm* lt = localtime_r(&t, &result); struct tm* lt = localtime_r(&t, &result);

View File

@ -30,7 +30,7 @@ static unsigned long int cached_read_diff = 0;
static unsigned long int cached_write_diff = 0; static unsigned long int cached_write_diff = 0;
static double cached_utilisation_diff = 0.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; static unsigned long long int cached_last_update = 0;
struct timeval tv; struct timeval tv;

View File

@ -19,7 +19,7 @@ static const int HostnameMeter_attributes[] = {
HOSTNAME HOSTNAME
}; };
static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) { static void HostnameMeter_updateValues(Meter* this, char* buffer, size_t size) {
(void) this; (void) this;
gethostname(buffer, size - 1); gethostname(buffer, size - 1);
} }

View File

@ -24,7 +24,7 @@ static const int LoadMeter_attributes[] = {
LOAD 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]); 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]); xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
} }
@ -40,7 +40,7 @@ static void LoadAverageMeter_display(const Object* cast, RichString* out) {
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer); 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; double five, fifteen;
Platform_getLoadAverage(&this->values[0], &five, &fifteen); Platform_getLoadAverage(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) { if (this->values[0] > this->total) {

View File

@ -19,7 +19,7 @@ static const int MemoryMeter_attributes[] = {
MEMORY_CACHE 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; int written;
Platform_setMemoryValues(this); Platform_setMemoryValues(this);

View File

@ -49,7 +49,7 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ
return this; 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"; const char* prefix = "KMGTPEZY";
unsigned long int powi = 1; unsigned long int powi = 1;
unsigned int powj = 1, precision = 2; unsigned int powj = 1, precision = 2;
@ -441,8 +441,7 @@ const MeterMode* const Meter_modes[] = {
/* Blank meter */ /* Blank meter */
static void BlankMeter_updateValues(Meter* this, char* buffer, int size) { static void BlankMeter_updateValues(ATTR_UNUSED Meter* this, char* buffer, size_t size) {
(void) this; (void) buffer; (void) size;
if (size > 0) { if (size > 0) {
*buffer = 0; *buffer = 0;
} }

View File

@ -26,7 +26,7 @@ typedef struct Meter_ Meter;
typedef void(*Meter_Init)(Meter*); typedef void(*Meter_Init)(Meter*);
typedef void(*Meter_Done)(Meter*); typedef void(*Meter_Done)(Meter*);
typedef void(*Meter_UpdateMode)(Meter*, int); 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 void(*Meter_Draw)(Meter*, int, int, int);
typedef struct MeterClass_ { typedef struct MeterClass_ {
@ -101,7 +101,7 @@ extern const MeterClass Meter_class;
Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type); 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); void Meter_delete(Object* cast);

View File

@ -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_txb_diff = 0;
static unsigned long int cached_txp_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; static unsigned long long int cached_last_update = 0;
struct timeval tv; struct timeval tv;

View File

@ -17,7 +17,7 @@ static const int SwapMeter_attributes[] = {
SWAP SWAP
}; };
static void SwapMeter_updateValues(Meter* this, char* buffer, int size) { static void SwapMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written; int written;
Platform_setSwapValues(this); Platform_setSwapValues(this);

View File

@ -23,7 +23,7 @@ static const int TasksMeter_attributes[] = {
TASKS_RUNNING 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; const ProcessList* pl = this->pl;
this->values[0] = pl->kernelThreads; this->values[0] = pl->kernelThreads;
this->values[1] = pl->userlandThreads; this->values[1] = pl->userlandThreads;

View File

@ -17,7 +17,7 @@ static const int UptimeMeter_attributes[] = {
UPTIME 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(); int totalseconds = Platform_getUptime();
if (totalseconds == -1) { if (totalseconds == -1) {
xSnprintf(buffer, len, "(unknown)"); xSnprintf(buffer, len, "(unknown)");

View File

@ -25,7 +25,7 @@ static const int PressureStallMeter_attributes[] = {
PRESSURE_STALL_THREEHUNDRED 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; const char* file;
if (strstr(Meter_name(this), "CPU")) { if (strstr(Meter_name(this), "CPU")) {
file = "cpu"; file = "cpu";

View File

@ -70,7 +70,7 @@ static bool isSelinuxEnforcing(void) {
return !!enforce; 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(); enabled = isSelinuxEnabled();
enforcing = isSelinuxEnforcing(); enforcing = isSelinuxEnforcing();

View File

@ -229,7 +229,7 @@ static void updateViaExec(void) {
fclose(commandOutput); 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); free(systemState);
systemState = NULL; systemState = NULL;
nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE; nFailedUnits = nInstalledJobs = nNames = nJobs = INVALID_VALUE;

View File

@ -11,7 +11,7 @@ static const int ZramMeter_attributes[] = {
ZRAM ZRAM
}; };
static void ZramMeter_updateValues(Meter* this, char* buffer, int size) { static void ZramMeter_updateValues(Meter* this, char* buffer, size_t size) {
int written; int written;
Platform_setZramValues(this); Platform_setZramValues(this);
@ -38,11 +38,15 @@ static void ZramMeter_updateValues(Meter* this, char* buffer, int size) {
} }
*buffer++ = ')'; *buffer++ = ')';
size--; size--;
if ((size -= written) > 0) { if (size <= 0) {
*buffer++ = '/'; return;
size--;
Meter_humanUnit(buffer, this->total, size);
} }
*buffer++ = '/';
size--;
if (size <= 0) {
return;
}
Meter_humanUnit(buffer, this->total, size);
} }
static void ZramMeter_display(const Object* cast, RichString* out) { static void ZramMeter_display(const Object* cast, RichString* out) {

View File

@ -33,7 +33,7 @@ void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
this->values[5] = stats->size; 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; int written;
Platform_setZfsArcValues(this); Platform_setZfsArcValues(this);

View File

@ -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]); 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); Platform_setZfsCompressedArcValues(this);
ZfsCompressedArcMeter_printRatioString(this, buffer, size); ZfsCompressedArcMeter_printRatioString(this, buffer, size);