[PATCH 06/15] testutilsqemuschema: Use automatic variable clearing where possible

Ján Tomko jtomko at redhat.com
Mon May 18 16:55:05 UTC 2020


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 at redhat.com>
>---
> 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 at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200518/43b3198d/attachment-0001.sig>


More information about the libvir-list mailing list