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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux