Skip to content

Commit

Permalink
Harden a pcp::pmda::cache::lookup overload
Browse files Browse the repository at this point in the history
This is really only needed for unit tests, since our fake libpcp-pmda
implementation may return `PMDA_CACHE_ACTIVE`, but does not intialise
the `name` parameter at all.  Still, it's good safe practice anyway.
  • Loading branch information
pcolby committed Mar 11, 2015
1 parent f2d56fa commit 33e02b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/pcp-cpp/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ lookup_result_type<Type> lookup(const pmInDom indom,
{
lookup_result_type<Type> result;
void * opaque;
result.name = NULL;
result.status = pmdaCacheLookup(indom, instance_id, &result.name, &opaque);
if (result.status < 0) {
throw pcp::exception(result.status);
}
if ((flags & require_active) && (result.status != PMDA_CACHE_ACTIVE)) {
std::ostringstream message;
message << "Cache entry " << indom << ':' << instance_id
<< " (\"" << result.name << "\") inactive";
message << "Cache entry " << indom << ':' << instance_id << " (";
if (result.name == NULL) {
message << "NULL";
} else {
message << '"' << result.name << '"';
}
message << ") inactive";
throw pcp::exception(result.status, message.str());
}
result.instance_id = instance_id;
Expand Down

0 comments on commit 33e02b5

Please sign in to comment.