From nobody Wed Nov 5 05:16:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532939756761854.78376318987; Mon, 30 Jul 2018 01:35:56 -0700 (PDT) Received: from localhost ([::1]:51182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk3ef-00054H-UQ for importer@patchew.org; Mon, 30 Jul 2018 04:35:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fk3cJ-0003Ot-QW for qemu-devel@nongnu.org; Mon, 30 Jul 2018 04:33:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fk3cG-0004WC-UN for qemu-devel@nongnu.org; Mon, 30 Jul 2018 04:33:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45066 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fk3cG-0004Vi-PT for qemu-devel@nongnu.org; Mon, 30 Jul 2018 04:33:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 615954219DB9; Mon, 30 Jul 2018 08:33:20 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 130BB2156701; Mon, 30 Jul 2018 08:33:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 922E411385CF; Mon, 30 Jul 2018 10:33:17 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 30 Jul 2018 10:33:00 +0200 Message-Id: <20180730083317.11765-7-armbru@redhat.com> In-Reply-To: <20180730083317.11765-1-armbru@redhat.com> References: <20180730083317.11765-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 30 Jul 2018 08:33:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 30 Jul 2018 08:33:20 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 06/23] qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Every printf()-like function sooner or later needs its vprintf()-like buddy. The next commit will need qobject_from_jsonf_nofail()'s buddy, and qdict_from_jsonf_nofail()'s buddy will be used later in this series. Add both. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Blake --- include/qapi/qmp/qjson.h | 4 ++++ qobject/qjson.c | 44 +++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index dc509d51ae..dce78583dc 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -18,8 +18,12 @@ QObject *qobject_from_json(const char *string, Error **e= rrp); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); =20 +QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QObject *qobject_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); +QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); =20 diff --git a/qobject/qjson.c b/qobject/qjson.c index 4a9dcff343..2e450231ff 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -59,6 +59,25 @@ QObject *qobject_from_json(const char *string, Error **e= rrp) return qobject_from_jsonv(string, NULL, errp); } =20 +/* + * Parse @string as JSON value with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QObject. It is never null. + */ +QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) +{ + va_list ap_copy; + QObject *obj; + + /* va_copy() is needed when va_list is an array type */ + va_copy(ap_copy, ap); + obj =3D qobject_from_jsonv(string, &ap_copy, &error_abort); + va_end(ap_copy); + + assert(obj); + return obj; +} + /* * Parse @string as JSON value with %-escapes interpolated. * Abort on error. Do not use with untrusted @string. @@ -70,13 +89,26 @@ QObject *qobject_from_jsonf_nofail(const char *string, = ...) va_list ap; =20 va_start(ap, string); - obj =3D qobject_from_jsonv(string, &ap, &error_abort); + obj =3D qobject_from_vjsonf_nofail(string, ap); va_end(ap); =20 - assert(obj); return obj; } =20 +/* + * Parse @string as JSON object with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QDict. It is never null. + */ +QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap) +{ + QDict *qdict; + + qdict =3D qobject_to(QDict, qobject_from_vjsonf_nofail(string, ap)); + assert(qdict); + return qdict; +} + /* * Parse @string as JSON object with %-escapes interpolated. * Abort on error. Do not use with untrusted @string. @@ -84,15 +116,13 @@ QObject *qobject_from_jsonf_nofail(const char *string,= ...) */ QDict *qdict_from_jsonf_nofail(const char *string, ...) { - QDict *obj; + QDict *qdict; va_list ap; =20 va_start(ap, string); - obj =3D qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort= )); + qdict =3D qdict_from_vjsonf_nofail(string, ap); va_end(ap); - - assert(obj); - return obj; + return qdict; } =20 typedef struct ToJsonIterState --=20 2.17.1