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:
Nathan Scott 2021-08-17 14:38:19 +10:00
parent fefff80631
commit c401ac3a98
2 changed files with 6 additions and 2 deletions

View File

@ -174,8 +174,9 @@ static Htop_Reaction actionSetSortColumn(State* st) {
char* name = NULL;
if (fields[i] >= LAST_PROCESSFIELD) {
DynamicColumn* column = Hashtable_get(dynamicColumns, fields[i]);
if (column)
name = xStrdup(column->caption ? column->caption : column->name);
if (column == NULL)
continue;
name = xStrdup(column->caption ? column->caption : column->name);
} else {
name = String_trim(Process_fields[fields[i]].name);
}

View File

@ -287,6 +287,9 @@ void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, Ri
int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, ProcessField key) {
const PCPDynamicColumn* column = Hashtable_get(p1->super.processList->dynamicColumns, key);
if (column == NULL)
return -1;
size_t metric = column->id;
unsigned int type = PCPMetric_type(metric);