Reduce scope of local variables

This commit is contained in:
Benny Baumann 2020-11-22 00:59:00 +01:00 committed by Christian Göttsche
parent ddda739cb2
commit 03f9a86918
4 changed files with 10 additions and 16 deletions

View File

@ -804,7 +804,6 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
struct nlattr* nlattr;
struct taskstats stats;
int rem;
unsigned long long int timeDelta;
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
nlhdr = nlmsg_hdr(nlmsg);
@ -817,7 +816,7 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats));
assert(lp->super.pid == (pid_t)stats.ac_pid);
timeDelta = stats.ac_etime * 1000 - lp->delay_read_time;
unsigned long long int timeDelta = stats.ac_etime * 1000 - lp->delay_read_time;
#define BOUNDS(x) (isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x))
#define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100)
lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total);

View File

@ -136,7 +136,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
char *s, **arg;
size_t len = 0, n;
size_t len = 0;
int i;
/*
@ -160,7 +160,7 @@ char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
*s = '\0';
for (i = 0; arg[i] != NULL; i++) {
n = strlcat(s, arg[i], len);
size_t n = strlcat(s, arg[i], len);
if (i == 0) {
/* TODO: rename all basenameEnd to basenameLen, make size_t */
*basenameEnd = MINIMUM(n, len - 1);
@ -188,23 +188,18 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
const Settings* settings = this->super.settings;
bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads;
struct kinfo_proc* kproc;
bool preExisting;
Process* proc;
OpenBSDProcess* fp;
int count = 0;
int i;
// use KERN_PROC_KTHREAD to also include kernel threads
struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
for (i = 0; i < count; i++) {
kproc = &kprocs[i];
for (int i = 0; i < count; i++) {
struct kinfo_proc* kproc = &kprocs[i];
preExisting = false;
proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
fp = (OpenBSDProcess*) proc;
bool preExisting = false;
Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
OpenBSDProcess* fp = (OpenBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))
|| (hideUserlandThreads && Process_isUserlandThread(proc)));

View File

@ -47,10 +47,10 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
}
static void ZfsArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
const Meter* this = (const Meter*)cast;
if (this->values[5] > 0) {
char buffer[50];
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
Meter_humanUnit(buffer, this->values[5], 50);

View File

@ -43,10 +43,10 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si
}
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
char buffer[50];
const Meter* this = (const Meter*)cast;
if (this->values[0] > 0) {
char buffer[50];
Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " Uncompressed, ");