From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542290958462119.68349389101797; Thu, 15 Nov 2018 06:09:18 -0800 (PST) Received: from localhost ([::1]:39002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIKb-0008Tp-Bg for importer@patchew.org; Thu, 15 Nov 2018 09:09:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIGi-0005YT-Ik for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIGd-0004If-RF for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3848) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGd-0004I9-MN for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:11 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05AB7C05D3F7; Thu, 15 Nov 2018 14:05:11 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98D79600C3; Thu, 15 Nov 2018 14:05:09 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:53 +0100 Message-Id: <20181115140501.7872-2-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 15 Nov 2018 14:05:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 1/9] cutils: add qemu_strtod() and qemu_strtod_finite() 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's provide a wrapper for strtod(). Signed-off-by: David Hildenbrand Reviewed-by: Eric Blake --- include/qemu/cutils.h | 2 ++ util/cutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 7071bfe2d4..756b41c193 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -146,6 +146,8 @@ int qemu_strtoi64(const char *nptr, const char **endptr= , int base, int64_t *result); int qemu_strtou64(const char *nptr, const char **endptr, int base, uint64_t *result); +int qemu_strtod(const char *nptr, const char **endptr, double *result); +int qemu_strtod_finite(const char *nptr, const char **endptr, double *resu= lt); =20 int parse_uint(const char *s, unsigned long long *value, char **endptr, int base); diff --git a/util/cutils.c b/util/cutils.c index 698bd315bd..7868a683e8 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -544,6 +544,44 @@ int qemu_strtou64(const char *nptr, const char **endpt= r, int base, return check_strtox_error(nptr, ep, endptr, errno); } =20 +/** + * Convert string @nptr to a double. + * + * Works like qemu_strtoul(), except it stores +/-HUGE_VAL on + * overflow/underflow. + */ +int qemu_strtod(const char *nptr, const char **endptr, double *result) +{ + char *ep; + + if (!nptr) { + if (endptr) { + *endptr =3D nptr; + } + return -EINVAL; + } + + errno =3D 0; + *result =3D strtod(nptr, &ep); + return check_strtox_error(nptr, ep, endptr, errno); +} + +/** + * Convert string @nptr to a finite double. + * + * Works like qemu_strtoul(), except it stores +/-HUGE_VAL on + * overflow/underflow. "NaN" or "inf" are rejcted with -EINVAL. + */ +int qemu_strtod_finite(const char *nptr, const char **endptr, double *resu= lt) +{ + int ret =3D qemu_strtod(nptr, endptr, result); + + if (!ret && !isfinite(*result)) { + return -EINVAL; + } + return ret; +} + /** * Searches for the first occurrence of 'c' in 's', and returns a pointer * to the trailing null byte if none was found. --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 15422911247071017.2009348267001; Thu, 15 Nov 2018 06:12:04 -0800 (PST) Received: from localhost ([::1]:39020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNINC-000298-8Q for importer@patchew.org; Thu, 15 Nov 2018 09:11:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIGh-0005YR-R3 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIGf-0004K0-QK for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGf-0004Jg-JN for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:13 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE8903001713; Thu, 15 Nov 2018 14:05:12 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48F9B600C3; Thu, 15 Nov 2018 14:05:11 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:54 +0100 Message-Id: <20181115140501.7872-3-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 15 Nov 2018 14:05:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 2/9] cutils: use qemu_strtod_finite() in do_strtosz() 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's use the new function. In order to do so, we have to convert all users of qemu_strtosz*() to pass a "const char **end" ptr. We will now also reject "inf" properly. Signed-off-by: David Hildenbrand --- include/qemu/cutils.h | 6 +++--- monitor.c | 2 +- tests/test-cutils.c | 14 +++++++------- util/cutils.c | 14 ++++++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 756b41c193..d2dad3057c 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -153,9 +153,9 @@ int parse_uint(const char *s, unsigned long long *value= , char **endptr, int base); int parse_uint_full(const char *s, unsigned long long *value, int base); =20 -int qemu_strtosz(const char *nptr, char **end, uint64_t *result); -int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result); -int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result); +int qemu_strtosz(const char *nptr, const char **end, uint64_t *result); +int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result); +int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *resu= lt); =20 /* used to print char* safely */ #define STR_OR_NULL(str) ((str) ? (str) : "null") diff --git a/monitor.c b/monitor.c index d39390c2f2..ee9893c785 100644 --- a/monitor.c +++ b/monitor.c @@ -3231,7 +3231,7 @@ static QDict *monitor_parse_arguments(Monitor *mon, { int ret; uint64_t val; - char *end; + const char *end; =20 while (qemu_isspace(*p)) { p++; diff --git a/tests/test-cutils.c b/tests/test-cutils.c index d85c3e0f6d..e21dcbf12b 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -1950,7 +1950,7 @@ static void test_qemu_strtou64_full_max(void) static void test_qemu_strtosz_simple(void) { const char *str; - char *endptr =3D NULL; + const char *endptr =3D NULL; int err; uint64_t res =3D 0xbaadf00d; =20 @@ -2017,7 +2017,7 @@ static void test_qemu_strtosz_units(void) const char *p =3D "1P"; const char *e =3D "1E"; int err; - char *endptr =3D NULL; + const char *endptr =3D NULL; uint64_t res =3D 0xbaadf00d; =20 /* default is M */ @@ -2066,7 +2066,7 @@ static void test_qemu_strtosz_float(void) { const char *str =3D "12.345M"; int err; - char *endptr =3D NULL; + const char *endptr =3D NULL; uint64_t res =3D 0xbaadf00d; =20 err =3D qemu_strtosz(str, &endptr, &res); @@ -2078,7 +2078,7 @@ static void test_qemu_strtosz_float(void) static void test_qemu_strtosz_invalid(void) { const char *str; - char *endptr =3D NULL; + const char *endptr =3D NULL; int err; uint64_t res =3D 0xbaadf00d; =20 @@ -2101,7 +2101,7 @@ static void test_qemu_strtosz_invalid(void) static void test_qemu_strtosz_trailing(void) { const char *str; - char *endptr =3D NULL; + const char *endptr =3D NULL; int err; uint64_t res =3D 0xbaadf00d; =20 @@ -2126,7 +2126,7 @@ static void test_qemu_strtosz_trailing(void) static void test_qemu_strtosz_erange(void) { const char *str; - char *endptr =3D NULL; + const char *endptr =3D NULL; int err; uint64_t res =3D 0xbaadf00d; =20 @@ -2160,7 +2160,7 @@ static void test_qemu_strtosz_metric(void) { const char *str =3D "12345k"; int err; - char *endptr =3D NULL; + const char *endptr =3D NULL; uint64_t res =3D 0xbaadf00d; =20 err =3D qemu_strtosz_metric(str, &endptr, &res); diff --git a/util/cutils.c b/util/cutils.c index 7868a683e8..dd61fb4558 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -206,19 +206,17 @@ static int64_t suffix_mul(char suffix, int64_t unit) * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on * other error. */ -static int do_strtosz(const char *nptr, char **end, +static int do_strtosz(const char *nptr, const char **end, const char default_suffix, int64_t unit, uint64_t *result) { int retval; - char *endptr; + const char *endptr; unsigned char c; int mul_required =3D 0; double val, mul, integral, fraction; =20 - errno =3D 0; - val =3D strtod(nptr, &endptr); - if (isnan(val) || endptr =3D=3D nptr || errno !=3D 0) { + if (qemu_strtod_finite(nptr, &endptr, &val)) { retval =3D -EINVAL; goto out; } @@ -259,17 +257,17 @@ out: return retval; } =20 -int qemu_strtosz(const char *nptr, char **end, uint64_t *result) +int qemu_strtosz(const char *nptr, const char **end, uint64_t *result) { return do_strtosz(nptr, end, 'B', 1024, result); } =20 -int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result) +int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result) { return do_strtosz(nptr, end, 'M', 1024, result); } =20 -int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result) +int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *resu= lt) { return do_strtosz(nptr, end, 'B', 1000, result); } --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 1542290834776497.8161928755658; Thu, 15 Nov 2018 06:07:14 -0800 (PST) Received: from localhost ([::1]:38993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIIW-0006MN-Cb for importer@patchew.org; Thu, 15 Nov 2018 09:07:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIGo-0005bk-AX for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIGj-0004Le-Ow for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18925) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGj-0004L5-K2 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:17 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26A259981B; Thu, 15 Nov 2018 14:05:16 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ED36600CD; Thu, 15 Nov 2018 14:05:12 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:55 +0100 Message-Id: <20181115140501.7872-4-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 15 Nov 2018 14:05:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 3/9] qapi: use qemu_strtod_finite() in string-input-visitor 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's use the new function. "NaN" and "inf" are now properly rejected. Signed-off-by: David Hildenbrand Reviewed-by: Eric Blake --- qapi/string-input-visitor.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index b3fdd0827d..b89c6c4e06 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -20,6 +20,7 @@ #include "qemu/option.h" #include "qemu/queue.h" #include "qemu/range.h" +#include "qemu/cutils.h" =20 =20 struct StringInputVisitor @@ -313,12 +314,9 @@ static void parse_type_number(Visitor *v, const char *= name, double *obj, Error **errp) { StringInputVisitor *siv =3D to_siv(v); - char *endp =3D (char *) siv->string; double val; =20 - errno =3D 0; - val =3D strtod(siv->string, &endp); - if (errno || endp =3D=3D siv->string || *endp) { + if (qemu_strtod_finite(siv->string, NULL, &val)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "number"); return; --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542291257544300.99322620571627; Thu, 15 Nov 2018 06:14:17 -0800 (PST) Received: from localhost ([::1]:39034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIPQ-0004bo-Er for importer@patchew.org; Thu, 15 Nov 2018 09:14:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIGt-0005cy-8o for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIGn-0004NL-VR for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGl-0004Ly-D6 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:19 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 068903097043; Thu, 15 Nov 2018 14:05:18 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 635706013F; Thu, 15 Nov 2018 14:05:16 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:56 +0100 Message-Id: <20181115140501.7872-5-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 15 Nov 2018 14:05:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 4/9] qapi: use qemu_strtod_finite() in qobject-input-visitor 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's use the new function. Just as current behavior, we have to consume the whole string (now it's just way clearer what's going on). Signed-off-by: David Hildenbrand Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster --- qapi/qobject-input-visitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 3e88b27f9e..07465f9947 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -562,19 +562,20 @@ static void qobject_input_type_number_keyval(Visitor = *v, const char *name, { QObjectInputVisitor *qiv =3D to_qiv(v); const char *str =3D qobject_input_get_keyval(qiv, name, errp); - char *endp; + double val; =20 if (!str) { return; } =20 - errno =3D 0; - *obj =3D strtod(str, &endp); - if (errno || endp =3D=3D str || *endp || !isfinite(*obj)) { + if (qemu_strtod_finite(str, NULL, &val)) { /* TODO report -ERANGE more nicely */ error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "number"); + return; } + + *obj =3D val; } =20 static void qobject_input_type_any(Visitor *v, const char *name, QObject *= *obj, --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542290861428630.1142219885742; Thu, 15 Nov 2018 06:07:41 -0800 (PST) Received: from localhost ([::1]:38994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIJ2-0006kW-Ab for importer@patchew.org; Thu, 15 Nov 2018 09:07:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIHH-0005r8-B0 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIH2-0004Tq-W8 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGx-0004Mc-3P for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C393058E35; Thu, 15 Nov 2018 14:05:19 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 354FD600C3; Thu, 15 Nov 2018 14:05:18 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:57 +0100 Message-Id: <20181115140501.7872-6-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 15 Nov 2018 14:05:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 5/9] test-string-input-visitor: add more tests 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test that very big/small values are not accepted and that ranges with only one element work. Rename expect4 to expect5, as we will be moving that to a separate ulist test after the rework. Signed-off-by: David Hildenbrand --- tests/test-string-input-visitor.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index 88e0e1aa9a..f55e0696c0 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -121,7 +121,8 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, int64_t expect1[] =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 }; int64_t expect2[] =3D { 32767, -32768, -32767 }; int64_t expect3[] =3D { INT64_MAX, INT64_MIN }; - uint64_t expect4[] =3D { UINT64_MAX }; + int64_t expect4[] =3D { 1 }; + uint64_t expect5[] =3D { UINT64_MAX }; Error *err =3D NULL; int64List *res =3D NULL; int64List *tail; @@ -140,8 +141,25 @@ static void test_visitor_in_intList(TestInputVisitorDa= ta *data, "-9223372036854775808,9223372036854775807"= ); check_ilist(v, expect3, ARRAY_SIZE(expect3)); =20 + v =3D visitor_input_test_init(data, "1-1"); + check_ilist(v, expect4, ARRAY_SIZE(expect4)); + v =3D visitor_input_test_init(data, "18446744073709551615"); - check_ulist(v, expect4, ARRAY_SIZE(expect4)); + check_ulist(v, expect5, ARRAY_SIZE(expect5)); + + /* Value too large */ + + v =3D visitor_input_test_init(data, "9223372036854775808"); + visit_type_int64List(v, NULL, &res, &err); + error_free_or_abort(&err); + g_assert(!res); + + /* Value too small */ + + v =3D visitor_input_test_init(data, "-9223372036854775809"); + visit_type_int64List(v, NULL, &res, &err); + error_free_or_abort(&err); + g_assert(!res); =20 /* Empty list */ =20 --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542291012613723.3199804951213; Thu, 15 Nov 2018 06:10:12 -0800 (PST) Received: from localhost ([::1]:39003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNILT-0000cC-4z for importer@patchew.org; Thu, 15 Nov 2018 09:10:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIHG-0005qN-CO for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIGw-0004RL-UG for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGr-0004Nm-Ao for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:27 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30AD53164989; Thu, 15 Nov 2018 14:05:22 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC453601A9; Thu, 15 Nov 2018 14:05:19 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:58 +0100 Message-Id: <20181115140501.7872-7-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 15 Nov 2018 14:05:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 6/9] qapi: rewrite string-input-visitor 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The input visitor has some problems right now, especially - unsigned type "Range" is used to process signed ranges, resulting in inconsistent behavior and ugly/magical code - uint64_t are parsed like int64_t, so big uint64_t values are not supported and error messages are misleading - lists/ranges of int64_t are accepted although no list is parsed and we should rather report an error - lists/ranges are preparsed using int64_t, making it hard to implement uint64_t values or uint64_t lists - types that don't support lists don't bail out - visiting beyond the end of a list is not handled properly So let's rewrite it by getting rid of usage of the type "Range" and properly supporting lists of int64_t and uint64_t (including ranges of both types), fixing the above mentioned issues. Lists of other types are not supported and will properly report an error. Virtual walks are now supported. Tests have to be fixed up: - Two BUGs were hardcoded that are fixed now - The string-input-visitor now actually returns a parsed list and not an ordered set. Signed-off-by: David Hildenbrand --- include/qapi/string-input-visitor.h | 4 +- qapi/string-input-visitor.c | 410 ++++++++++++++++------------ tests/test-string-input-visitor.c | 18 +- 3 files changed, 239 insertions(+), 193 deletions(-) diff --git a/include/qapi/string-input-visitor.h b/include/qapi/string-inpu= t-visitor.h index 33551340e3..921f3875b9 100644 --- a/include/qapi/string-input-visitor.h +++ b/include/qapi/string-input-visitor.h @@ -19,8 +19,8 @@ typedef struct StringInputVisitor StringInputVisitor; =20 /* * The string input visitor does not implement support for visiting - * QAPI structs, alternates, null, or arbitrary QTypes. It also - * requires a non-null list argument to visit_start_list(). + * QAPI structs, alternates, null, or arbitrary QTypes. Only flat lists + * of integers (except type "size") are supported. */ Visitor *string_input_visitor_new(const char *str); =20 diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index b89c6c4e06..4113be01fb 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -4,10 +4,10 @@ * Copyright Red Hat, Inc. 2012-2016 * * Author: Paolo Bonzini + * David Hildenbrand * * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. * See the COPYING.LIB file in the top-level directory. - * */ =20 #include "qemu/osdep.h" @@ -18,21 +18,39 @@ #include "qapi/qmp/qerror.h" #include "qapi/qmp/qnull.h" #include "qemu/option.h" -#include "qemu/queue.h" -#include "qemu/range.h" #include "qemu/cutils.h" =20 +typedef enum ListMode { + /* no list parsing active / no list expected */ + LM_NONE, + /* we have an unparsed string remaining */ + LM_UNPARSED, + /* we have an unfinished int64 range */ + LM_INT64_RANGE, + /* we have an unfinished uint64 range */ + LM_UINT64_RANGE, + /* we have parsed the string completely and no range is remaining */ + LM_END, +} ListMode; + +typedef union RangeElement { + int64_t i64; + uint64_t u64; +} RangeElement; =20 struct StringInputVisitor { Visitor visitor; =20 - GList *ranges; - GList *cur_range; - int64_t cur; + /* List parsing state */ + ListMode lm; + RangeElement rangeNext; + RangeElement rangeEnd; + const char *unparsed_string; + void *list; =20 + /* The original string to parse */ const char *string; - void *list; /* Only needed for sanity checking the caller */ }; =20 static StringInputVisitor *to_siv(Visitor *v) @@ -40,136 +58,43 @@ static StringInputVisitor *to_siv(Visitor *v) return container_of(v, StringInputVisitor, visitor); } =20 -static void free_range(void *range, void *dummy) -{ - g_free(range); -} - -static int parse_str(StringInputVisitor *siv, const char *name, Error **er= rp) -{ - char *str =3D (char *) siv->string; - long long start, end; - Range *cur; - char *endptr; - - if (siv->ranges) { - return 0; - } - - if (!*str) { - return 0; - } - - do { - errno =3D 0; - start =3D strtoll(str, &endptr, 0); - if (errno =3D=3D 0 && endptr > str) { - if (*endptr =3D=3D '\0') { - cur =3D g_malloc0(sizeof(*cur)); - range_set_bounds(cur, start, start); - siv->ranges =3D range_list_insert(siv->ranges, cur); - cur =3D NULL; - str =3D NULL; - } else if (*endptr =3D=3D '-') { - str =3D endptr + 1; - errno =3D 0; - end =3D strtoll(str, &endptr, 0); - if (errno =3D=3D 0 && endptr > str && start <=3D end && - (start > INT64_MAX - 65536 || - end < start + 65536)) { - if (*endptr =3D=3D '\0') { - cur =3D g_malloc0(sizeof(*cur)); - range_set_bounds(cur, start, end); - siv->ranges =3D range_list_insert(siv->ranges, cur= ); - cur =3D NULL; - str =3D NULL; - } else if (*endptr =3D=3D ',') { - str =3D endptr + 1; - cur =3D g_malloc0(sizeof(*cur)); - range_set_bounds(cur, start, end); - siv->ranges =3D range_list_insert(siv->ranges, cur= ); - cur =3D NULL; - } else { - goto error; - } - } else { - goto error; - } - } else if (*endptr =3D=3D ',') { - str =3D endptr + 1; - cur =3D g_malloc0(sizeof(*cur)); - range_set_bounds(cur, start, start); - siv->ranges =3D range_list_insert(siv->ranges, cur); - cur =3D NULL; - } else { - goto error; - } - } else { - goto error; - } - } while (str); - - return 0; -error: - g_list_foreach(siv->ranges, free_range, NULL); - g_list_free(siv->ranges); - siv->ranges =3D NULL; - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "an int64 value or range"); - return -1; -} - -static void -start_list(Visitor *v, const char *name, GenericList **list, size_t size, - Error **errp) +static void start_list(Visitor *v, const char *name, GenericList **list, + size_t size, Error **errp) { StringInputVisitor *siv =3D to_siv(v); =20 - /* We don't support visits without a list */ - assert(list); + /* properly set the list parsing state */ + assert(siv->lm =3D=3D LM_NONE); siv->list =3D list; + siv->unparsed_string =3D siv->string; =20 - if (parse_str(siv, name, errp) < 0) { - *list =3D NULL; - return; - } - - siv->cur_range =3D g_list_first(siv->ranges); - if (siv->cur_range) { - Range *r =3D siv->cur_range->data; - if (r) { - siv->cur =3D range_lob(r); + if (!siv->string[0]) { + if (list) { + *list =3D NULL; } - *list =3D g_malloc0(size); + siv->lm =3D LM_END; } else { - *list =3D NULL; + if (list) { + *list =3D g_malloc0(size); + } + siv->lm =3D LM_UNPARSED; } } =20 static GenericList *next_list(Visitor *v, GenericList *tail, size_t size) { StringInputVisitor *siv =3D to_siv(v); - Range *r; =20 - if (!siv->ranges || !siv->cur_range) { + switch (siv->lm) { + case LM_END: return NULL; - } - - r =3D siv->cur_range->data; - if (!r) { - return NULL; - } - - if (!range_contains(r, siv->cur)) { - siv->cur_range =3D g_list_next(siv->cur_range); - if (!siv->cur_range) { - return NULL; - } - r =3D siv->cur_range->data; - if (!r) { - return NULL; - } - siv->cur =3D range_lob(r); + case LM_INT64_RANGE: + case LM_UINT64_RANGE: + case LM_UNPARSED: + /* we have an unparsed string or something left in a range */ + break; + default: + abort(); } =20 tail->next =3D g_malloc0(size); @@ -179,88 +104,215 @@ static GenericList *next_list(Visitor *v, GenericLis= t *tail, size_t size) static void check_list(Visitor *v, Error **errp) { const StringInputVisitor *siv =3D to_siv(v); - Range *r; - GList *cur_range; =20 - if (!siv->ranges || !siv->cur_range) { + switch (siv->lm) { + case LM_INT64_RANGE: + case LM_UINT64_RANGE: + case LM_UNPARSED: + error_setg(errp, "Fewer list elements expected"); return; - } - - r =3D siv->cur_range->data; - if (!r) { + case LM_END: return; + default: + abort(); } - - if (!range_contains(r, siv->cur)) { - cur_range =3D g_list_next(siv->cur_range); - if (!cur_range) { - return; - } - r =3D cur_range->data; - if (!r) { - return; - } - } - - error_setg(errp, "Range contains too many values"); } =20 static void end_list(Visitor *v, void **obj) { StringInputVisitor *siv =3D to_siv(v); =20 + assert(siv->lm !=3D LM_NONE); assert(siv->list =3D=3D obj); + siv->list =3D NULL; + siv->unparsed_string =3D NULL; + siv->lm =3D LM_NONE; +} + +static int try_parse_int64_list_entry(StringInputVisitor *siv, int64_t *ob= j) +{ + const char *endptr; + int64_t start, end; + + if (qemu_strtoi64(siv->unparsed_string, &endptr, 0, &start)) { + return -EINVAL; + } + end =3D start; + + switch (endptr[0]) { + case '\0': + siv->unparsed_string =3D endptr; + break; + case ',': + siv->unparsed_string =3D endptr + 1; + break; + case '-': + /* parse the end of the range */ + if (qemu_strtoi64(endptr + 1, &endptr, 0, &end)) { + return -EINVAL; + } + if (start > end) { + return -EINVAL; + } + switch (endptr[0]) { + case '\0': + siv->unparsed_string =3D endptr; + break; + case ',': + siv->unparsed_string =3D endptr + 1; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + + /* we have a proper range (with maybe only one element) */ + siv->lm =3D LM_INT64_RANGE; + siv->rangeNext.i64 =3D start; + siv->rangeEnd.i64 =3D end; + return 0; } =20 static void parse_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { StringInputVisitor *siv =3D to_siv(v); - - if (parse_str(siv, name, errp) < 0) { + int64_t val; + + switch (siv->lm) { + case LM_NONE: + /* just parse a simple int64, bail out if not completely consumed = */ + if (qemu_strtoi64(siv->string, NULL, 0, &val)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", "int64"); + return; + } + *obj =3D val; return; + case LM_UNPARSED: + if (try_parse_int64_list_entry(siv, obj)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "= null", + "list of int64 values or ranges"); + return; + } + assert(siv->lm =3D=3D LM_INT64_RANGE); + /* FALLTHROUGH */ + case LM_INT64_RANGE: + /* return the next element in the range */ + assert(siv->rangeNext.i64 <=3D siv->rangeEnd.i64); + *obj =3D siv->rangeNext.i64++; + + if (siv->rangeNext.i64 > siv->rangeEnd.i64 || *obj =3D=3D INT64_MA= X) { + /* end of range, check if there is more to parse */ + if (siv->unparsed_string[0]) { + siv->lm =3D LM_UNPARSED; + } else { + siv->lm =3D LM_END; + } + } + return; + case LM_END: + error_setg(errp, "Fewer list elements expected"); + return; + default: + abort(); } +} =20 - if (!siv->ranges) { - goto error; - } - - if (!siv->cur_range) { - Range *r; +static int try_parse_uint64_list_entry(StringInputVisitor *siv, uint64_t *= obj) +{ + const char *endptr; + uint64_t start, end; =20 - siv->cur_range =3D g_list_first(siv->ranges); - if (!siv->cur_range) { - goto error; + /* parse a simple uint64 or range */ + if (qemu_strtou64(siv->unparsed_string, &endptr, 0, &start)) { + return -EINVAL; + } + end =3D start; + + switch (endptr[0]) { + case '\0': + siv->unparsed_string =3D endptr; + break; + case ',': + siv->unparsed_string =3D endptr + 1; + break; + case '-': + /* parse the end of the range */ + if (qemu_strtou64(endptr + 1, &endptr, 0, &end)) { + return -EINVAL; } - - r =3D siv->cur_range->data; - if (!r) { - goto error; + if (start > end) { + return -EINVAL; } - - siv->cur =3D range_lob(r); + switch (endptr[0]) { + case '\0': + siv->unparsed_string =3D endptr; + break; + case ',': + siv->unparsed_string =3D endptr + 1; + break; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; } =20 - *obj =3D siv->cur; - siv->cur++; - return; - -error: - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "an int64 value or range"); + /* we have a proper range (with maybe only one element) */ + siv->lm =3D LM_UINT64_RANGE; + siv->rangeNext.u64 =3D start; + siv->rangeEnd.u64 =3D end; + return 0; } =20 static void parse_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { - /* FIXME: parse_type_int64 mishandles values over INT64_MAX */ - int64_t i; - Error *err =3D NULL; - parse_type_int64(v, name, &i, &err); - if (err) { - error_propagate(errp, err); - } else { - *obj =3D i; + StringInputVisitor *siv =3D to_siv(v); + uint64_t val; + + switch (siv->lm) { + case LM_NONE: + /* just parse a simple uint64, bail out if not completely consumed= */ + if (qemu_strtou64(siv->string, NULL, 0, &val)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "= null", + "uint64"); + return; + } + *obj =3D val; + return; + case LM_UNPARSED: + if (try_parse_uint64_list_entry(siv, obj)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "= null", + "list of uint64 values or ranges"); + return; + } + assert(siv->lm =3D=3D LM_UINT64_RANGE); + /* FALLTHROUGH */ + case LM_UINT64_RANGE: + /* return the next element in the range */ + assert(siv->rangeNext.u64 <=3D siv->rangeEnd.u64); + *obj =3D siv->rangeNext.u64++; + + if (siv->rangeNext.u64 > siv->rangeEnd.u64 || *obj =3D=3D UINT64_M= AX) { + /* end of range, check if there is more to parse */ + if (siv->unparsed_string[0]) { + siv->lm =3D LM_UNPARSED; + } else { + siv->lm =3D LM_END; + } + } + return; + case LM_END: + error_setg(errp, "Fewer list elements expected"); + return; + default: + abort(); } } =20 @@ -271,6 +323,7 @@ static void parse_type_size(Visitor *v, const char *nam= e, uint64_t *obj, Error *err =3D NULL; uint64_t val; =20 + assert(siv->lm =3D=3D LM_NONE); parse_option_size(name, siv->string, &val, &err); if (err) { error_propagate(errp, err); @@ -285,6 +338,7 @@ static void parse_type_bool(Visitor *v, const char *nam= e, bool *obj, { StringInputVisitor *siv =3D to_siv(v); =20 + assert(siv->lm =3D=3D LM_NONE); if (!strcasecmp(siv->string, "on") || !strcasecmp(siv->string, "yes") || !strcasecmp(siv->string, "true")) { @@ -307,6 +361,7 @@ static void parse_type_str(Visitor *v, const char *name= , char **obj, { StringInputVisitor *siv =3D to_siv(v); =20 + assert(siv->lm =3D=3D LM_NONE); *obj =3D g_strdup(siv->string); } =20 @@ -316,6 +371,7 @@ static void parse_type_number(Visitor *v, const char *n= ame, double *obj, StringInputVisitor *siv =3D to_siv(v); double val; =20 + assert(siv->lm =3D=3D LM_NONE); if (qemu_strtod_finite(siv->string, NULL, &val)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "number"); @@ -330,9 +386,10 @@ static void parse_type_null(Visitor *v, const char *na= me, QNull **obj, { StringInputVisitor *siv =3D to_siv(v); =20 + assert(siv->lm =3D=3D LM_NONE); *obj =3D NULL; =20 - if (!siv->string || siv->string[0]) { + if (siv->string[0]) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "null"); return; @@ -345,8 +402,6 @@ static void string_input_free(Visitor *v) { StringInputVisitor *siv =3D to_siv(v); =20 - g_list_foreach(siv->ranges, free_range, NULL); - g_list_free(siv->ranges); g_free(siv); } =20 @@ -372,5 +427,6 @@ Visitor *string_input_visitor_new(const char *str) v->visitor.free =3D string_input_free; =20 v->string =3D str; + v->lm =3D LM_NONE; return &v->visitor; } diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index f55e0696c0..a198aedfce 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -92,16 +92,6 @@ static void check_ulist(Visitor *v, uint64_t *expected, = size_t n) uint64List *tail; int i; =20 - /* BUG: unsigned numbers above INT64_MAX don't work */ - for (i =3D 0; i < n; i++) { - if (expected[i] > INT64_MAX) { - Error *err =3D NULL; - visit_type_uint64List(v, NULL, &res, &err); - error_free_or_abort(&err); - return; - } - } - visit_type_uint64List(v, NULL, &res, &error_abort); tail =3D res; for (i =3D 0; i < n; i++) { @@ -117,10 +107,10 @@ static void check_ulist(Visitor *v, uint64_t *expecte= d, size_t n) static void test_visitor_in_intList(TestInputVisitorData *data, const void *unused) { - /* Note: the visitor *sorts* ranges *unsigned* */ - int64_t expect1[] =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 }; + int64_t expect1[] =3D { 1, 2, 0, 2, 3, 4, 20, 5, 6, 7, + 8, 9, 1, 2, 3, 4, 5, 6, 7, 8 }; int64_t expect2[] =3D { 32767, -32768, -32767 }; - int64_t expect3[] =3D { INT64_MAX, INT64_MIN }; + int64_t expect3[] =3D { INT64_MIN, INT64_MAX }; int64_t expect4[] =3D { 1 }; uint64_t expect5[] =3D { UINT64_MAX }; Error *err =3D NULL; @@ -207,7 +197,7 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, visit_type_int64(v, NULL, &tail->value, &err); g_assert_cmpint(tail->value, =3D=3D, 0); visit_type_int64(v, NULL, &val, &err); - g_assert_cmpint(val, =3D=3D, 1); /* BUG */ + error_free_or_abort(&err); visit_check_list(v, &error_abort); visit_end_list(v, (void **)&res); =20 --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542291364673832.1242653011257; Thu, 15 Nov 2018 06:16:04 -0800 (PST) Received: from localhost ([::1]:39049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIR9-0005ry-Jc for importer@patchew.org; Thu, 15 Nov 2018 09:16:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIHG-0005qg-OM for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIH2-0004Tr-W9 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46295) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIGx-0004PP-3O for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6E433DE0E; Thu, 15 Nov 2018 14:05:26 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65087601A9; Thu, 15 Nov 2018 14:05:22 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:04:59 +0100 Message-Id: <20181115140501.7872-8-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 15 Nov 2018 14:05:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 7/9] test-string-input-visitor: use virtual walk 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now support virtual walks, so use that instead. Signed-off-by: David Hildenbrand Reviewed-by: Markus Armbruster --- tests/test-string-input-visitor.c | 36 +++++++++++-------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index a198aedfce..4ad4cc0b56 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -115,7 +115,6 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, uint64_t expect5[] =3D { UINT64_MAX }; Error *err =3D NULL; int64List *res =3D NULL; - int64List *tail; Visitor *v; int64_t val; =20 @@ -169,39 +168,28 @@ static void test_visitor_in_intList(TestInputVisitorD= ata *data, =20 v =3D visitor_input_test_init(data, "0,2-3"); =20 - /* Would be simpler if the visitor genuinely supported virtual walks */ - visit_start_list(v, NULL, (GenericList **)&res, sizeof(*res), - &error_abort); - tail =3D res; - visit_type_int64(v, NULL, &tail->value, &error_abort); - g_assert_cmpint(tail->value, =3D=3D, 0); - tail =3D (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*= res)); - g_assert(tail); - visit_type_int64(v, NULL, &tail->value, &error_abort); - g_assert_cmpint(tail->value, =3D=3D, 2); - tail =3D (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*= res)); - g_assert(tail); + visit_start_list(v, NULL, NULL, 0, &error_abort); + visit_type_int64(v, NULL, &val, &error_abort); + g_assert_cmpint(val, =3D=3D, 0); + visit_type_int64(v, NULL, &val, &error_abort); + g_assert_cmpint(val, =3D=3D, 2); =20 visit_check_list(v, &err); error_free_or_abort(&err); - visit_end_list(v, (void **)&res); - - qapi_free_int64List(res); + visit_end_list(v, NULL); =20 /* Visit beyond end of list */ + v =3D visitor_input_test_init(data, "0"); =20 - visit_start_list(v, NULL, (GenericList **)&res, sizeof(*res), - &error_abort); - tail =3D res; - visit_type_int64(v, NULL, &tail->value, &err); - g_assert_cmpint(tail->value, =3D=3D, 0); + visit_start_list(v, NULL, NULL, 0, &error_abort); + visit_type_int64(v, NULL, &val, &err); + g_assert_cmpint(val, =3D=3D, 0); visit_type_int64(v, NULL, &val, &err); error_free_or_abort(&err); - visit_check_list(v, &error_abort); - visit_end_list(v, (void **)&res); =20 - qapi_free_int64List(res); + visit_check_list(v, &error_abort); + visit_end_list(v, NULL); } =20 static void test_visitor_in_bool(TestInputVisitorData *data, --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154229150512723.716474289969256; Thu, 15 Nov 2018 06:18:25 -0800 (PST) Received: from localhost ([::1]:39055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNITH-00077C-Ir for importer@patchew.org; Thu, 15 Nov 2018 09:18:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIHN-0005w1-BQ for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIHM-0004er-9B for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIHI-0004QP-7k for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:54 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06F51811D7; Thu, 15 Nov 2018 14:05:29 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02624600C3; Thu, 15 Nov 2018 14:05:26 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:05:00 +0100 Message-Id: <20181115140501.7872-9-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 15 Nov 2018 14:05:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 8/9] test-string-input-visitor: split off uint64 list tests 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Basically copy all int64 list tests but adapt them to work on uint64 instead. The values for very big/very small values have to be adapted. Signed-off-by: David Hildenbrand Reviewed-by: Markus Armbruster --- tests/test-string-input-visitor.c | 94 +++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index 4ad4cc0b56..d2ec453252 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -112,7 +112,6 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, int64_t expect2[] =3D { 32767, -32768, -32767 }; int64_t expect3[] =3D { INT64_MIN, INT64_MAX }; int64_t expect4[] =3D { 1 }; - uint64_t expect5[] =3D { UINT64_MAX }; Error *err =3D NULL; int64List *res =3D NULL; Visitor *v; @@ -133,9 +132,6 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, v =3D visitor_input_test_init(data, "1-1"); check_ilist(v, expect4, ARRAY_SIZE(expect4)); =20 - v =3D visitor_input_test_init(data, "18446744073709551615"); - check_ulist(v, expect5, ARRAY_SIZE(expect5)); - /* Value too large */ =20 v =3D visitor_input_test_init(data, "9223372036854775808"); @@ -192,6 +188,94 @@ static void test_visitor_in_intList(TestInputVisitorDa= ta *data, visit_end_list(v, NULL); } =20 +static void test_visitor_in_uintList(TestInputVisitorData *data, + const void *unused) +{ + uint64_t expect1[] =3D { 1, 2, 0, 2, 3, 4, 20, 5, 6, 7, + 8, 9, 1, 2, 3, 4, 5, 6, 7, 8 }; + uint64_t expect2[] =3D { 32767, -32768, -32767 }; + uint64_t expect3[] =3D { INT64_MIN, INT64_MAX }; + uint64_t expect4[] =3D { 1 }; + uint64_t expect5[] =3D { UINT64_MAX }; + Error *err =3D NULL; + uint64List *res =3D NULL; + Visitor *v; + uint64_t val; + + /* Valid lists */ + + v =3D visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); + check_ulist(v, expect1, ARRAY_SIZE(expect1)); + + v =3D visitor_input_test_init(data, "32767,-32768--32767"); + check_ulist(v, expect2, ARRAY_SIZE(expect2)); + + v =3D visitor_input_test_init(data, + "-9223372036854775808,9223372036854775807"= ); + check_ulist(v, expect3, ARRAY_SIZE(expect3)); + + v =3D visitor_input_test_init(data, "1-1"); + check_ulist(v, expect4, ARRAY_SIZE(expect4)); + + v =3D visitor_input_test_init(data, "18446744073709551615"); + check_ulist(v, expect5, ARRAY_SIZE(expect5)); + + /* Value too large */ + + v =3D visitor_input_test_init(data, "18446744073709551616"); + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + g_assert(!res); + + /* Value too small */ + + v =3D visitor_input_test_init(data, "-18446744073709551616"); + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + g_assert(!res); + + /* Empty list */ + + v =3D visitor_input_test_init(data, ""); + visit_type_uint64List(v, NULL, &res, &error_abort); + g_assert(!res); + + /* Not a list */ + + v =3D visitor_input_test_init(data, "not an uint list"); + + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + g_assert(!res); + + /* Unvisited list tail */ + + v =3D visitor_input_test_init(data, "0,2-3"); + + visit_start_list(v, NULL, NULL, 0, &error_abort); + visit_type_uint64(v, NULL, &val, &error_abort); + g_assert_cmpuint(val, =3D=3D, 0); + visit_type_uint64(v, NULL, &val, &error_abort); + g_assert_cmpuint(val, =3D=3D, 2); + + visit_check_list(v, &err); + error_free_or_abort(&err); + visit_end_list(v, NULL); + + /* Visit beyond end of list */ + + v =3D visitor_input_test_init(data, "0"); + + visit_start_list(v, NULL, NULL, 0, &error_abort); + visit_type_uint64(v, NULL, &val, &err); + g_assert_cmpuint(val, =3D=3D, 0); + visit_type_uint64(v, NULL, &val, &err); + error_free_or_abort(&err); + + visit_check_list(v, &error_abort); + visit_end_list(v, NULL); +} + static void test_visitor_in_bool(TestInputVisitorData *data, const void *unused) { @@ -352,6 +436,8 @@ int main(int argc, char **argv) &in_visitor_data, test_visitor_in_int); input_visitor_test_add("/string-visitor/input/intList", &in_visitor_data, test_visitor_in_intList); + input_visitor_test_add("/string-visitor/input/uintList", + &in_visitor_data, test_visitor_in_uintList); input_visitor_test_add("/string-visitor/input/bool", &in_visitor_data, test_visitor_in_bool); input_visitor_test_add("/string-visitor/input/number", --=20 2.17.2 From nobody Thu Nov 6 16:00:39 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542291179602132.17702424751155; Thu, 15 Nov 2018 06:12:59 -0800 (PST) Received: from localhost ([::1]:39022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIOA-0002zX-Fn for importer@patchew.org; Thu, 15 Nov 2018 09:12:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNIHS-0005zU-EJ for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:06:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNIHM-0004fj-ME for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:06:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37106) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gNIHM-0004SJ-F4 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 09:05:56 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E83C13082A47; Thu, 15 Nov 2018 14:05:32 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-224.ams2.redhat.com [10.36.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AE90620CA; Thu, 15 Nov 2018 14:05:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 15:05:01 +0100 Message-Id: <20181115140501.7872-10-david@redhat.com> In-Reply-To: <20181115140501.7872-1-david@redhat.com> References: <20181115140501.7872-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 15 Nov 2018 14:05:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1 9/9] test-string-input-visitor: add range overflow tests 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: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's make sure that the range handling code can properly deal with ranges that end at the biggest possible number. Signed-off-by: David Hildenbrand Reviewed-by: Markus Armbruster --- tests/test-string-input-visitor.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index d2ec453252..86b1f9d593 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -112,6 +112,7 @@ static void test_visitor_in_intList(TestInputVisitorDat= a *data, int64_t expect2[] =3D { 32767, -32768, -32767 }; int64_t expect3[] =3D { INT64_MIN, INT64_MAX }; int64_t expect4[] =3D { 1 }; + int64_t expect5[] =3D { INT64_MAX - 2, INT64_MAX - 1, INT64_MAX }; Error *err =3D NULL; int64List *res =3D NULL; Visitor *v; @@ -132,6 +133,10 @@ static void test_visitor_in_intList(TestInputVisitorDa= ta *data, v =3D visitor_input_test_init(data, "1-1"); check_ilist(v, expect4, ARRAY_SIZE(expect4)); =20 + v =3D visitor_input_test_init(data, + "9223372036854775805-9223372036854775807"); + check_ilist(v, expect5, ARRAY_SIZE(expect5)); + /* Value too large */ =20 v =3D visitor_input_test_init(data, "9223372036854775808"); @@ -197,6 +202,7 @@ static void test_visitor_in_uintList(TestInputVisitorDa= ta *data, uint64_t expect3[] =3D { INT64_MIN, INT64_MAX }; uint64_t expect4[] =3D { 1 }; uint64_t expect5[] =3D { UINT64_MAX }; + uint64_t expect6[] =3D { UINT64_MAX - 2, UINT64_MAX - 1, UINT64_MAX }; Error *err =3D NULL; uint64List *res =3D NULL; Visitor *v; @@ -220,6 +226,10 @@ static void test_visitor_in_uintList(TestInputVisitorD= ata *data, v =3D visitor_input_test_init(data, "18446744073709551615"); check_ulist(v, expect5, ARRAY_SIZE(expect5)); =20 + v =3D visitor_input_test_init(data, + "18446744073709551613-18446744073709551615= "); + check_ulist(v, expect6, ARRAY_SIZE(expect6)); + /* Value too large */ =20 v =3D visitor_input_test_init(data, "18446744073709551616"); --=20 2.17.2