From 33e02b53cc7ddd55dcfedb334bc650ad9c7b3c9a Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Thu, 12 Mar 2015 07:45:00 +1100 Subject: [PATCH] Harden a pcp::pmda::cache::lookup overload 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. --- include/pcp-cpp/cache.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/pcp-cpp/cache.hpp b/include/pcp-cpp/cache.hpp index b26c852..ceadd12 100644 --- a/include/pcp-cpp/cache.hpp +++ b/include/pcp-cpp/cache.hpp @@ -86,14 +86,20 @@ lookup_result_type lookup(const pmInDom indom, { lookup_result_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;