cleanups and fixes, thanks to cppcheck and gcc -Wextra

This commit is contained in:
Hisham Muhammad 2011-10-25 00:05:46 +00:00
parent 75080ce79d
commit d1b1cbc757
8 changed files with 21 additions and 27 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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)\"

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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);