Skip to content

Commit

Permalink
Ensure possible NULL pointer values dealt with defensively
Browse files Browse the repository at this point in the history
Coverity scanning shows a couple of locations where a NULL
pointer dereference could happen; updated code to ensure it
cannot.
  • Loading branch information
natoscott committed Aug 31, 2023
1 parent b0b6ff7 commit 7b544ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,10 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
if (screen)
screen->allBranchesCollapsed = atoi(option[1]);
} else if (String_eq(option[0], ".dynamic")) {
if (screen)
if (screen) {
free_and_xStrdup(&screen->dynamic, option[1]);
Platform_addDynamicScreen(screen);
Platform_addDynamicScreen(screen);
}
}
String_freeArray(option);
}
Expand Down
4 changes: 3 additions & 1 deletion pcp/Instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ static void Instance_writeField(const Row* super, RichString* str, RowField fiel
const Settings* settings = super->host->settings;
DynamicColumn* column = Hashtable_get(settings->dynamicColumns, field);
PCPDynamicColumn* cp = (PCPDynamicColumn*) column;
const pmDesc* descp = Metric_desc(cp->id);
if (!cp)
return;

pmAtomValue atom;
pmAtomValue *ap = &atom;
const pmDesc* descp = Metric_desc(cp->id);
if (!Metric_instance(cp->id, instid, this->offset, ap, descp->type))
ap = NULL;

Expand Down

0 comments on commit 7b544ec

Please sign in to comment.