From nobody Mon Feb 9 20:36:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588186199; cv=none; d=zohomail.com; s=zohoarc; b=MhLYywHOtmdOvvKFaQEtCEeObKFpX8gEmPX151l0KKeobXGL9S8ben2oUO30/QvY9JlxeQgfpNmpwPHjY6cqPYsBx3HiEq5FagFbKn/bpy+v06vPSB8pR2TBmvJkFvVMqCb+5x3dvPKfqflc+Ce13mnibK+OC4ESTeAe6EtIKSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588186199; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JLkitdA5FI+v1TckQ7HDTnFLWqwop/yiDeDDV/cdu90=; b=LTbBxktMFg91oadPtrnllQelzd7QW+GjpUdy+HzsO1CrjXEWyVcT1L+UZbylJltBnPcAFNB8iJjlHxQP/nEnxXhdtBOEAF9zFAbtnQ0/Y4o6ToI9TYlU7c4OooY4ewFk6775+ybZJ/2UyJWtsN/bZBetNFKXc0cYajaZmPKHAAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1588186199829475.708092328121; Wed, 29 Apr 2020 11:49:59 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-55-HEOnLPnTM5-w3qis8TB65w-1; Wed, 29 Apr 2020 14:49:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3117580572E; Wed, 29 Apr 2020 18:49:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 094735D78D; Wed, 29 Apr 2020 18:49:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B4D631806B0D; Wed, 29 Apr 2020 18:49:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03TInS10001542 for ; Wed, 29 Apr 2020 14:49:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14B7C5C241; Wed, 29 Apr 2020 18:49:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EA635C1BE for ; Wed, 29 Apr 2020 18:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588186198; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JLkitdA5FI+v1TckQ7HDTnFLWqwop/yiDeDDV/cdu90=; b=EwAr0zhqwF8Xv/JgwKfPRTajJ+48fmatgrG1wT4ftX0TMmyfDZJBA4b+lqzaep7xSDaJ5o RoKrK5DmkAGRXKH1xDoBlbY5jUwoWEpRZUsy0G91Cm4kEviB7ufpDj7tEpTi3XZNcbKKzt yKemejqH60ZYaJc3pl0bUdWlQyaF+3c= X-MC-Unique: HEOnLPnTM5-w3qis8TB65w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/15] testutilsqemuschema: Use automatic variable clearing where possible Date: Wed, 29 Apr 2020 20:49:06 +0200 Message-Id: <7d7a6c9434931a2f052a46a03798cde569124cf7.1588185999.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Refactor all cleanup to avoid manual clearing, unnecessary labels and return value variables. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- 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 =3D opaque; - virJSONValuePtr keymember =3D NULL; + g_autoptr(virJSONValue) keymember =3D NULL; const char *keytype; virJSONValuePtr keyschema =3D NULL; - int ret =3D -1; + int rc; virBufferStrcat(data->debug, key, ": ", NULL); /* lookup 'member' entry for key */ if (!(keymember =3D testQEMUSchemaStealObjectMemberByName(key, data->r= ootmembers))) { - 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 =3D virJSONValueObjectGetString(keymember, "type")) || !(keyschema =3D 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 =3D -2; - goto cleanup; + return -2; } /* recurse */ - ret =3D testQEMUSchemaValidateRecurse(value, keyschema, data->schema, + rc =3D testQEMUSchemaValidateRecurse(value, keyschema, data->schema, data->debug); - cleanup: virBufferAddLit(data->debug, "\n"); - virJSONValueFree(keymember); - return ret; + return rc; } @@ -188,13 +185,12 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValue= Ptr root, virBufferPtr debug) { size_t i; - virJSONValuePtr variants =3D NULL; + g_autoptr(virJSONValue) variants =3D NULL; virJSONValuePtr variant; virJSONValuePtr variantschema; virJSONValuePtr variantschemamembers; virJSONValuePtr rootmembers; const char *varianttype =3D NULL; - int ret =3D -1; if (!(variants =3D virJSONValueObjectStealArray(root, "variants"))) { virBufferAddLit(debug, "ERROR: missing 'variants' in schema\n"); @@ -214,8 +210,7 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValuePt= r root, if (!varianttype) { virBufferAsprintf(debug, "ERROR: variant '%s' for discriminator '%= s' not found\n", variantname, variantfield); - goto cleanup; - + return -1; } if (!(variantschema =3D virHashLookup(schema, varianttype)) || @@ -223,8 +218,7 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValuePt= r root, virBufferAsprintf(debug, "ERROR: missing schema or schema members for var= iant '%s'(%s)\n", variantname, varianttype); - ret =3D -2; - goto cleanup; + return -2; } rootmembers =3D virJSONValueObjectGetArray(root, "members"); @@ -232,15 +226,10 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValue= Ptr root, if (virJSONValueArrayForeachSteal(variantschemamembers, testQEMUSchemaValidateObjectMergeVar= iantMember, rootmembers) < 0) { - ret =3D -2; - goto cleanup; + return -2; } - ret =3D 0; - - cleanup: - virJSONValueFree(variants); - return ret; + return 0; } @@ -269,10 +258,9 @@ testQEMUSchemaValidateObject(virJSONValuePtr obj, { struct testQEMUSchemaValidateObjectMemberData data =3D { NULL, schema, debug, false }; - virJSONValuePtr localroot =3D NULL; + g_autoptr(virJSONValue) localroot =3D NULL; const char *variantfield; const char *variantname; - int ret =3D -1; if (virJSONValueGetType(obj) !=3D VIR_JSON_TYPE_OBJECT) { virBufferAddLit(debug, "ERROR: not an object"); @@ -283,23 +271,21 @@ testQEMUSchemaValidateObject(virJSONValuePtr obj, virBufferAdjustIndent(debug, 3); /* copy schema */ - if (!(localroot =3D virJSONValueCopy(root))) { - ret =3D -2; - goto cleanup; - } + if (!(localroot =3D virJSONValueCopy(root))) + return -2; /* remove variant */ if ((variantfield =3D virJSONValueObjectGetString(localroot, "tag"))) { if (!(variantname =3D virJSONValueObjectGetString(obj, variantfiel= d))) { virBufferAsprintf(debug, "ERROR: missing variant discriminator= attribute '%s'\n", variantfield); - goto cleanup; + return -1; } if (testQEMUSchemaValidateObjectMergeVariant(localroot, variantfie= ld, variantname, schema, debug) < 0) - goto cleanup; + return -1; } @@ -308,26 +294,21 @@ testQEMUSchemaValidateObject(virJSONValuePtr obj, if (virJSONValueObjectForeachKeyValue(obj, testQEMUSchemaValidateObjectMemb= er, &data) < 0) - goto cleanup; + return -1; /* check missing mandatory values */ if (virJSONValueArrayForeachSteal(data.rootmembers, testQEMUSchemaValidateObjectMandator= yMember, &data) < 0) { - ret =3D -2; - goto cleanup; + return -2; } if (data.missingMandatory) - goto cleanup; + return -1; virBufferAdjustIndent(debug, -3); virBufferAddLit(debug, "} OK"); - ret =3D 0; - - cleanup: - virJSONValueFree(localroot); - return ret; + return 0; } @@ -570,11 +551,11 @@ testQEMUSchemaValidateCommand(const char *command, virJSONValuePtr testQEMUSchemaGetLatest(const char* arch) { - char *capsLatestFile =3D NULL; - char *capsLatest =3D NULL; + g_autofree char *capsLatestFile =3D NULL; + g_autofree char *capsLatest =3D NULL; char *schemaReply; char *end; - virJSONValuePtr reply =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValuePtr schema =3D NULL; if (!(capsLatestFile =3D testQemuGetLatestCapsForArch(arch, "replies")= )) { @@ -585,14 +566,14 @@ testQEMUSchemaGetLatest(const char* arch) VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile); if (virTestLoadFile(capsLatestFile, &capsLatest) < 0) - goto cleanup; + return NULL; if (!(schemaReply =3D strstr(capsLatest, "\"execute\": \"query-qmp-sch= ema\"")) || !(schemaReply =3D strstr(schemaReply, "\n\n")) || !(end =3D strstr(schemaReply + 2, "\n\n"))) { VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%= s'", capsLatestFile); - goto cleanup; + return NULL; } schemaReply +=3D 2; @@ -601,19 +582,15 @@ testQEMUSchemaGetLatest(const char* arch) if (!(reply =3D virJSONValueFromString(schemaReply))) { VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%= s'", capsLatestFile); - goto cleanup; + return NULL; } if (!(schema =3D virJSONValueObjectStealArray(reply, "return"))) { VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'", capsLatestFile); - goto cleanup; + return NULL; } - cleanup: - VIR_FREE(capsLatestFile); - VIR_FREE(capsLatest); - virJSONValueFree(reply); return schema; } --=20 2.26.2