diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index d81f01ba77..0d77a2f90d 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -231,12 +231,12 @@ qemuAgentIOProcessLine(qemuAgent *agent, return -1; } - if (virJSONValueObjectHasKey(obj, "QMP") == 1) { + if (virJSONValueObjectHasKey(obj, "QMP")) { return 0; - } else if (virJSONValueObjectHasKey(obj, "event") == 1) { + } else if (virJSONValueObjectHasKey(obj, "event")) { return qemuAgentIOProcessEvent(agent, obj); - } else if (virJSONValueObjectHasKey(obj, "error") == 1 || - virJSONValueObjectHasKey(obj, "return") == 1) { + } else if (virJSONValueObjectHasKey(obj, "error") || + virJSONValueObjectHasKey(obj, "return")) { if (msg) { if (msg->sync) { unsigned long long id; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 941596563a..2469165728 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -203,14 +203,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, return -1; } - if (virJSONValueObjectHasKey(obj, "QMP") == 1) { + if (virJSONValueObjectHasKey(obj, "QMP")) { return 0; - } else if (virJSONValueObjectHasKey(obj, "event") == 1) { + } else if (virJSONValueObjectHasKey(obj, "event")) { PROBE(QEMU_MONITOR_RECV_EVENT, "mon=%p event=%s", mon, line); return qemuMonitorJSONIOProcessEvent(mon, obj); - } else if (virJSONValueObjectHasKey(obj, "error") == 1 || - virJSONValueObjectHasKey(obj, "return") == 1) { + } else if (virJSONValueObjectHasKey(obj, "error") || + virJSONValueObjectHasKey(obj, "return")) { PROBE(QEMU_MONITOR_RECV_REPLY, "mon=%p reply=%s", mon, line); if (msg) { @@ -270,7 +270,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, memset(&msg, 0, sizeof(msg)); - if (virJSONValueObjectHasKey(cmd, "execute") == 1) { + if (virJSONValueObjectHasKey(cmd, "execute")) { g_autofree char *id = qemuMonitorNextCommandID(mon); if (virJSONValueObjectAppendString(cmd, "id", id) < 0) { diff --git a/src/util/virjson.c b/src/util/virjson.c index 53f8cdff95..ef59b5deb4 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -798,21 +798,21 @@ virJSONValueArrayConcat(virJSONValue *a, } -int +bool virJSONValueObjectHasKey(virJSONValue *object, const char *key) { size_t i; if (object->type != VIR_JSON_TYPE_OBJECT) - return -1; + return false; for (i = 0; i < object->data.object.npairs; i++) { if (STREQ(object->data.object.pairs[i].key, key)) - return 1; + return true; } - return 0; + return false; } diff --git a/src/util/virjson.h b/src/util/virjson.h index aced48a538..ce181dcb82 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -88,7 +88,7 @@ int virJSONValueArrayConcat(virJSONValue *a, virJSONValue *c); -int +bool virJSONValueObjectHasKey(virJSONValue *object, const char *key); virJSONValue * diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 4a0fb8d944..d431e7b3fc 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -289,7 +289,7 @@ testQEMUSchemaValidateObjectMandatoryMember(size_t pos G_GNUC_UNUSED, { struct testQEMUSchemaValidateObjectMemberData *data = opaque; - if (virJSONValueObjectHasKey(item, "default") != 1) { + if (!virJSONValueObjectHasKey(item, "default")) { virBufferAsprintf(data->ctxt->debug, "ERROR: missing mandatory attribute '%s'\n", NULLSTR(virJSONValueObjectGetString(item, "name"))); data->missingMandatory = true;