From c401ac3a98563f84e1957445f4c5643186e0e9d3 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 17 Aug 2021 14:38:19 +1000 Subject: 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. --- Action.c | 5 +++-- pcp/PCPDynamicColumn.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Action.c b/Action.c index 5d774587..6e804f68 100644 --- a/Action.c +++ b/Action.c @@ -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); } diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c index 141978a7..4051e101 100644 --- a/pcp/PCPDynamicColumn.c +++ b/pcp/PCPDynamicColumn.c @@ -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); -- cgit v1.2.3