[Cluster-devel] [fence-virt PATCH] Don't reference out-of-scope temporary
Zane Bitter
zbitter at redhat.com
Wed Aug 24 16:40:42 UTC 2011
The string on which we were calling c_str() was a temporary, so the C
string returned would no longer be valid. This issue was detected by a
Coverity scan.
Signed-off-by: Zane Bitter <zbitter at redhat.com>
---
server/libvirt-qpid.cpp | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/server/libvirt-qpid.cpp b/server/libvirt-qpid.cpp
index d133346..eb35d49 100644
--- a/server/libvirt-qpid.cpp
+++ b/server/libvirt-qpid.cpp
@@ -120,7 +120,7 @@ int
do_lq_request(struct lq_info *info, const char *vm_name,
const char *action)
{
- const char *vm_state = NULL;
+ std::string vm_state;
const char *property = "name";
if (is_uuid(vm_name) == 1) {
property = "uuid";
@@ -171,15 +171,15 @@ do_lq_request(struct lq_info *info, const char *vm_name,
goto out;
}
- vm_state = domain.getProperty("state").asString().c_str();
+ vm_state = domain.getProperty("state").asString();
std::cout << vm_name << " " << vm_state << std::endl;
int r;
- if (!strcmp( vm_state, "running" ) ||
- !strcmp( vm_state, "idle" ) ||
- !strcmp( vm_state, "paused" ) ||
- !strcmp( vm_state, "no state" ) ) {
+ if (vm_state == "running" ||
+ vm_state == "idle" ||
+ vm_state == "paused" ||
+ vm_state == "no state") {
r = RESP_OFF;
} else {
r = 0;
More information about the Cluster-devel
mailing list