summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-08-31 16:56:32 +1000
committerNathan Scott <nathans@redhat.com>2020-08-31 16:56:32 +1000
commit800d8c735d3085e90ecef426ba4ebda7b80df46b (patch)
tree4f2756ac9f73cae26ee46caf88f1dfb1a7d5ff53
parentfdf8a28e6071175f69d924cbd3599a169d18c259 (diff)
parent5c99c6e942d5346bdac77d11eece9e2d60db4191 (diff)
Merge branch 'cov_fixes' of https://github.com/cgzones/htop into cgzones-cov_fixes
-rw-r--r--InfoScreen.c2
-rw-r--r--linux/LinuxProcessList.c15
2 files changed, 9 insertions, 8 deletions
diff --git a/InfoScreen.c b/InfoScreen.c
index 93120006..5c586bdd 100644
--- a/InfoScreen.c
+++ b/InfoScreen.c
@@ -80,7 +80,7 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
va_start(ap, fmt);
attrset(CRT_colors[METER_TEXT]);
mvhline(0, 0, ' ', COLS);
- wmove(stdscr, 0, 0);
+ (void) wmove(stdscr, 0, 0);
vw_printw(stdscr, fmt, ap);
attrset(CRT_colors[DEFAULT_COLOR]);
this->display->needsRedraw = true;
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 6d3d0348..e426785f 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -275,7 +275,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
} else if (String_startsWith(buffer, "cpu")) {
cpus++;
} else if (String_startsWith(buffer, "btime ")) {
- sscanf(buffer, "btime %lld\n", &btime);
+ if (sscanf(buffer, "btime %lld\n", &btime) != 1)
+ CRT_fatalError("Failed to parse btime from " PROCSTATFILE);
break;
}
} while(true);
@@ -1062,9 +1063,9 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
}
static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) {
- unsigned long long int dbufSize;
- unsigned long long int dnodeSize;
- unsigned long long int bonusSize;
+ unsigned long long int dbufSize = 0;
+ unsigned long long int dnodeSize = 0;
+ unsigned long long int bonusSize = 0;
FILE* file = fopen(PROCARCSTATSFILE, "r");
if (file == NULL) {
@@ -1142,10 +1143,10 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
if (!ok) buffer[0] = '\0';
if (i == 0)
- sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
+ (void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
else {
int cpuid;
- sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
+ (void) sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
assert(cpuid == i - 1);
}
// Guest time is already accounted in usertime
@@ -1235,7 +1236,7 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) {
(sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) ||
(sscanf(buffer, "cpu MHz: %lf", &frequency) == 1)
) {
- if (cpuid < 0) {
+ if (cpuid < 0 || cpuid > (cpus - 1)) {
CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line");
}

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