mirror of https://github.com/xzeldon/htop.git
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:
parent
d9224c66a4
commit
e1ce141bc3
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
5
Meter.c
5
Meter.c
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
4
Meter.h
4
Meter.h
|
@ -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_ {
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)");
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue