On a Wednesday in 2020, Peter Krempa wrote:
Refactor all cleanup to avoid manual clearing, unnecessary labels and return value variables. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- tests/testutilsqemuschema.c | 81 +++++++++++++------------------------ 1 file changed, 29 insertions(+), 52 deletions(-) diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 60409a0f91..a43cbe2f91 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -123,36 +123,33 @@ testQEMUSchemaValidateObjectMember(const char *key, void *opaque) { struct testQEMUSchemaValidateObjectMemberData *data = opaque; - virJSONValuePtr keymember = NULL; + g_autoptr(virJSONValue) keymember = NULL; const char *keytype; virJSONValuePtr keyschema = NULL; - int ret = -1; + int rc; virBufferStrcat(data->debug, key, ": ", NULL); /* lookup 'member' entry for key */ if (!(keymember = testQEMUSchemaStealObjectMemberByName(key, data->rootmembers))) { - virBufferAddLit(data->debug, "ERROR: attribute not in schema"); - goto cleanup; + virBufferAddLit(data->debug, "ERROR: attribute not in schema\n"); + return -1; } /* lookup schema entry for keytype */ if (!(keytype = virJSONValueObjectGetString(keymember, "type")) || !(keyschema = virHashLookup(data->schema, keytype))) { - virBufferAsprintf(data->debug, "ERROR: can't find schema for type '%s'", + virBufferAsprintf(data->debug, "ERROR: can't find schema for type '%s'\n", NULLSTR(keytype)); - ret = -2; - goto cleanup; + return -2; } /* recurse */ - ret = testQEMUSchemaValidateRecurse(value, keyschema, data->schema, + rc = testQEMUSchemaValidateRecurse(value, keyschema, data->schema, data->debug);
Indentation is off.
- cleanup: virBufferAddLit(data->debug, "\n"); - virJSONValueFree(keymember); - return ret; + return rc; }
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature