summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-10-25 00:05:46 +0000
committerHisham Muhammad <hisham@gobolinux.org>2011-10-25 00:05:46 +0000
commitd1b1cbc75715eb4f40a444d3a1d2741b3617b1f0 (patch)
treed7ba15bd1300fff66757d0178ed91b156312bf7c
parent75080ce79d2fb8ae895659326dacf688c8cb7ce9 (diff)
cleanups and fixes, thanks to cppcheck and gcc -Wextra
-rw-r--r--BatteryMeter.c7
-rw-r--r--LoadAverageMeter.c2
-rw-r--r--Makefile.am2
-rw-r--r--Meter.c5
-rw-r--r--Object.c6
-rw-r--r--Process.c8
-rw-r--r--ProcessList.c16
-rw-r--r--UptimeMeter.c2
8 files changed, 21 insertions, 27 deletions
diff --git a/BatteryMeter.c b/BatteryMeter.c
index 1690a969..f7323aa9 100644
--- a/BatteryMeter.c
+++ b/BatteryMeter.c
@@ -45,7 +45,7 @@ static unsigned long int parseUevent(FILE * file, const char *key) {
}
static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) {
- const DIR *batteryDir;
+ DIR* batteryDir;
const struct dirent *dirEntries;
const char batteryPath[] = PROCDIR "/acpi/battery/";
@@ -89,6 +89,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
snprintf((char *) infoPath, sizeof infoPath, "%s%s/%s", batteryPath, newEntry->content, fileName);
if ((file = fopen(infoPath, "r")) == NULL) {
+ closedir(batteryDir);
return 0;
}
@@ -107,7 +108,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
free(myList);
free(newEntry);
- closedir((DIR *) batteryDir);
+ closedir(batteryDir);
return total;
}
@@ -274,6 +275,7 @@ static double getSysBatData() {
} else {
//reset file pointer
if (fseek(file, 0, SEEK_SET) < 0) {
+ closedir(power_supplyDir);
fclose(file);
return 0;
}
@@ -285,6 +287,7 @@ static double getSysBatData() {
} else {
//reset file pointer
if (fseek(file, 0, SEEK_SET) < 0) {
+ closedir(power_supplyDir);
fclose(file);
return 0;
}
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index 7646ad65..02c8ad5e 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -23,7 +23,7 @@ static inline void LoadAverageMeter_scan(double* one, double* five, double* fift
*one = 0; *five = 0; *fifteen = 0;
FILE *fd = fopen(PROCDIR "/loadavg", "r");
if (fd) {
- int total = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
+ int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen,
&activeProcs, &totalProcs, &lastProc);
(void) total;
assert(total == 6);
diff --git a/Makefile.am b/Makefile.am
index 1c09ae90..919c987a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,7 @@ applications_DATA = htop.desktop
pixmapdir = $(datadir)/pixmaps
pixmap_DATA = htop.png
-htop_CFLAGS = -pedantic -Wall -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED
+htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED
AM_CFLAGS =
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
diff --git a/Meter.c b/Meter.c
index 57862364..8c3cc50f 100644
--- a/Meter.c
+++ b/Meter.c
@@ -5,7 +5,6 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
-#define _GNU_SOURCE
#include "RichString.h"
#include "Meter.h"
#include "Object.h"
@@ -275,11 +274,10 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
for (int i = 0; i < w; i++)
bar[i] = ' ';
- const size_t barOffset = w - MIN(strlen(buffer), w);
+ const size_t barOffset = w - MIN((int)strlen(buffer), w);
snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
// First draw in the bar[] buffer...
- double total = 0.0;
int offset = 0;
for (int i = 0; i < type->items; i++) {
double value = this->values[i];
@@ -302,7 +300,6 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
}
}
offset = nextOffset;
- total += this->values[i];
}
// ...then print the buffer.
diff --git a/Object.c b/Object.c
index 4e61c543..f8eb20db 100644
--- a/Object.c
+++ b/Object.c
@@ -48,10 +48,4 @@ void Object_setClass(void* this, char* class) {
((Object*)this)->class = class;
}
-static void Object_display(Object* this, RichString* out) {
- char objAddress[50];
- sprintf(objAddress, "%s @ %p", this->class, (void*) this);
- RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress);
-}
-
#endif
diff --git a/Process.c b/Process.c
index a64bdd77..0632278a 100644
--- a/Process.c
+++ b/Process.c
@@ -235,7 +235,7 @@ void Process_getMaxPid() {
FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r");
if (!file) return;
int maxPid = 4194303;
- fscanf(file, "%d", &maxPid);
+ fscanf(file, "%32d", &maxPid);
fclose(file);
if (maxPid > 99999) {
Process_fieldTitles[PID] = " PID ";
@@ -287,7 +287,7 @@ static void Process_humanNumber(Process* this, RichString* str, unsigned long nu
}
}
-static void Process_colorNumber(Process* this, RichString* str, unsigned long long number) {
+static void Process_colorNumber(RichString* str, unsigned long long number) {
char buffer[14];
if (number > 10000000000) {
snprintf(buffer, 13, "%11lld ", number / 1000);
@@ -486,8 +486,8 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
case WCHAR: snprintf(buffer, n, "%12llu ", this->io_wchar); break;
case SYSCR: snprintf(buffer, n, "%10llu ", this->io_syscr); break;
case SYSCW: snprintf(buffer, n, "%10llu ", this->io_syscw); break;
- case RBYTES: Process_colorNumber(this, str, this->io_read_bytes); return;
- case WBYTES: Process_colorNumber(this, str, this->io_write_bytes); return;
+ case RBYTES: Process_colorNumber(str, this->io_read_bytes); return;
+ case WBYTES: Process_colorNumber(str, this->io_write_bytes); return;
case CNCLWB: snprintf(buffer, n, "%10llu ", this->io_cancelled_write_bytes); break;
case IO_READ_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_read_bps); return;
case IO_WRITE_RATE: Process_outputRate(this, str, attr, buffer, n, this->io_rate_write_bps); return;
diff --git a/ProcessList.c b/ProcessList.c
index f3cc40f1..c986cecd 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -438,7 +438,7 @@ static bool ProcessList_readStatmFile(Process* process, const char* dirname, con
if (!file)
return false;
- int num = fscanf(file, "%d %d %d %d %d %d %d",
+ int num = fscanf(file, "%32d %32d %32d %32d %32d %32d %32d",
&process->m_size, &process->m_resident, &process->m_share,
&process->m_trs, &process->m_lrs, &process->m_drs,
&process->m_dt);
@@ -460,13 +460,13 @@ static void ProcessList_readOpenVZData(Process* process, const char* dirname, co
if (!file)
return;
fscanf(file,
- "%*u %*s %*c %*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %*u %*u %*u %*u %*u "
- "%*u %*u %u %u",
+ "%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %*32u %*32u %*32u %*32u %*32u "
+ "%*32u %*32u %32u %32u",
&process->vpid, &process->ctid);
fclose(file);
}
diff --git a/UptimeMeter.c b/UptimeMeter.c
index d676850d..3aa78977 100644
--- a/UptimeMeter.c
+++ b/UptimeMeter.c
@@ -22,7 +22,7 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
double uptime = 0;
FILE* fd = fopen(PROCDIR "/uptime", "r");
if (fd) {
- fscanf(fd, "%lf", &uptime);
+ fscanf(fd, "%64lf", &uptime);
fclose(fd);
}
int totalseconds = (int) ceil(uptime);

© 2014-2024 Faster IT GmbH | imprint | privacy policy