{
const char *objstr;
virJSONValue *values = NULL;
- virJSONValue *value;
size_t i;
if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) {
objstr = virJSONValueGetString(obj);
- if (!(values = virJSONValueObjectGetArray(root, "values"))) {
- virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
- NULLSTR(virJSONValueObjectGetString(root, "name")));
- return -2;
- }
-
- for (i = 0; i < virJSONValueArraySize(values); i++) {
- value = virJSONValueArrayGet(values, i);
+ if ((values = virJSONValueObjectGetArray(root, "values"))) {
+ for (i = 0; i < virJSONValueArraySize(values); i++) {
+ virJSONValue *value = virJSONValueArrayGet(values, i);
- if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
- virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
- return 0;
+ if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
+ virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
+ return 0;
+ }
}
+
+ virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
+ NULLSTR(objstr));
+ return -1;
}
- virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
- NULLSTR(objstr));
- return -1;
+ virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
+ NULLSTR(virJSONValueObjectGetString(root, "name")));
+ return -2;
}