From 48a418bac9d1829ff38e9b1397335e3f2c4c9383 Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Wed, 8 Apr 2015 20:14:21 +1000 Subject: [PATCH] Assert that the pmParseDebug parameter is not null 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. --- test/unit/src/fake_libpcp.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/src/fake_libpcp.cpp b/test/unit/src/fake_libpcp.cpp index afe6776..abb16ec 100644 --- a/test/unit/src/fake_libpcp.cpp +++ b/test/unit/src/fake_libpcp.cpp @@ -67,6 +67,9 @@ 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" @@ -74,7 +77,7 @@ int __pmParseDebug(const char *spec) // 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::max() : result;