Skip to content

Commit

Permalink
Assert that the pmParseDebug parameter is not null
Browse files Browse the repository at this point in the history
This should also resolve Coverity Scan issue 89187, which correctly
points out, that since later code was checking for NULL, spec could
possibly be NULL when being passed to strcmp, which would then result
in a NULL dereference.

In this case, we're simply educating Coverity Scan, and ourselves, that
in fact, the spec parameter can never be NULL.
  • Loading branch information
pcolby committed Apr 8, 2015
1 parent d18f5a0 commit 48a418b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/unit/src/fake_libpcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ void __pmNotifyErr(int /*priority*/, const char */*message*/, ...)

int __pmParseDebug(const char *spec)
{
// The first this the real __pmParseDebug does is dereference spec.
assert(spec != NULL);

// Allow our unit tests to invoke an error response.
if (strcmp(spec, "invalid") == 0) {
return PM_ERR_FAULT; // "QA fault injected"
}

// Lazily convert the spec to an int. Note, this is *not* the same logic as
// the real __pmParseDebug function.
const int result = (spec == NULL) ? 0 : atoi(spec);
const int result = atoi(spec);

// The real __pmParseDebug does support "-1" as a synonym for "all".
return (result == -1) ? std::numeric_limits<int>::max() : result;
Expand Down

0 comments on commit 48a418b

Please sign in to comment.