diff options
author | Nathan Scott <nathans@redhat.com> | 2021-08-17 14:38:19 +1000 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2021-08-17 14:41:40 +1000 |
commit | c401ac3a98563f84e1957445f4c5643186e0e9d3 (patch) | |
tree | 1f43c17ad890b1da80544473ea1b6ba9839f4bf3 | |
parent | fefff80631e86f0296a2621a3699b16de60b86c6 (diff) |
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.
-rw-r--r-- | Action.c | 5 | ||||
-rw-r--r-- | pcp/PCPDynamicColumn.c | 3 |
2 files changed, 6 insertions, 2 deletions
@@ -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); |