mirror of https://github.com/xzeldon/htop.git
Ensure DynamicColumn hash lookups never see NULL pointers
This cannot happen in these code locations, but for the purposes of static checkers like Coverity scan (and for future proofing), add two more guards on NULL hash table entry pointers.
This commit is contained in:
parent
fefff80631
commit
c401ac3a98
5
Action.c
5
Action.c
|
@ -174,8 +174,9 @@ static Htop_Reaction actionSetSortColumn(State* st) {
|
||||||
char* name = NULL;
|
char* name = NULL;
|
||||||
if (fields[i] >= LAST_PROCESSFIELD) {
|
if (fields[i] >= LAST_PROCESSFIELD) {
|
||||||
DynamicColumn* column = Hashtable_get(dynamicColumns, fields[i]);
|
DynamicColumn* column = Hashtable_get(dynamicColumns, fields[i]);
|
||||||
if (column)
|
if (column == NULL)
|
||||||
name = xStrdup(column->caption ? column->caption : column->name);
|
continue;
|
||||||
|
name = xStrdup(column->caption ? column->caption : column->name);
|
||||||
} else {
|
} else {
|
||||||
name = String_trim(Process_fields[fields[i]].name);
|
name = String_trim(Process_fields[fields[i]].name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,9 @@ void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, Ri
|
||||||
int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, ProcessField key) {
|
int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, ProcessField key) {
|
||||||
const PCPDynamicColumn* column = Hashtable_get(p1->super.processList->dynamicColumns, key);
|
const PCPDynamicColumn* column = Hashtable_get(p1->super.processList->dynamicColumns, key);
|
||||||
|
|
||||||
|
if (column == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
size_t metric = column->id;
|
size_t metric = column->id;
|
||||||
unsigned int type = PCPMetric_type(metric);
|
unsigned int type = PCPMetric_type(metric);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue