From nobody Wed Nov 5 05:21:42 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 1532586047921321.6396134478034; Wed, 25 Jul 2018 23:20:47 -0700 (PDT) Received: from localhost ([::1]:59037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiZdb-0001br-B8 for importer@patchew.org; Thu, 26 Jul 2018 02:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiZbu-0000g0-2j for qemu-devel@nongnu.org; Thu, 26 Jul 2018 02:18:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiZbr-0001VV-2L for qemu-devel@nongnu.org; Thu, 26 Jul 2018 02:18:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56064 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 1fiZbq-0001V0-T8 for qemu-devel@nongnu.org; Thu, 26 Jul 2018 02:18:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60CDF81663C5; Thu, 26 Jul 2018 06:18:46 +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 0E6D7111AF3C; Thu, 26 Jul 2018 06:18:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C549211385E4; Thu, 26 Jul 2018 08:18:44 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 26 Jul 2018 08:18:44 +0200 Message-Id: <20180726061844.25992-3-armbru@redhat.com> In-Reply-To: <20180726061844.25992-1-armbru@redhat.com> References: <20180726061844.25992-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 26 Jul 2018 06:18:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 26 Jul 2018 06:18:46 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' 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 2/2] qstring: Move qstring_from_substr()'s @end one to the right 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: liujunjie23@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qstring_from_substr() takes the index of the substring's first and last character. qstring_from_substr(s, 0, SIZE_MAX) denotes an empty substring. Awkward. Shift the end index one to the right. This simplifies both qstring_from_substr() and its callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- block/blkdebug.c | 2 +- block/blkverify.c | 2 +- block/nbd.c | 2 +- qobject/qstring.c | 6 +++--- tests/check-qobject.c | 2 +- tests/check-qstring.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 0457bf5b66..0759452925 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -305,7 +305,7 @@ static void blkdebug_parse_filename(const char *filenam= e, QDict *options, =20 if (c !=3D filename) { QString *config_path; - config_path =3D qstring_from_substr(filename, 0, c - filename - 1); + config_path =3D qstring_from_substr(filename, 0, c - filename); qdict_put(options, "config", config_path); } =20 diff --git a/block/blkverify.c b/block/blkverify.c index da97ee5927..89bf4386e3 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -80,7 +80,7 @@ static void blkverify_parse_filename(const char *filename= , QDict *options, } =20 /* TODO Implement option pass-through and set raw.filename here */ - raw_path =3D qstring_from_substr(filename, 0, c - filename - 1); + raw_path =3D qstring_from_substr(filename, 0, c - filename); qdict_put(options, "x-raw", raw_path); =20 /* TODO Allow multi-level nesting and set file.filename here */ diff --git a/block/nbd.c b/block/nbd.c index b198ad775f..e87699fb73 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -109,7 +109,7 @@ static int nbd_parse_uri(const char *filename, QDict *o= ptions) /* strip braces from literal IPv6 address */ if (uri->server[0] =3D=3D '[') { host =3D qstring_from_substr(uri->server, 1, - strlen(uri->server) - 2); + strlen(uri->server) - 1); } else { host =3D qstring_from_str(uri->server); } diff --git a/qobject/qstring.c b/qobject/qstring.c index 7990569c5a..6afb8b005c 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -41,12 +41,12 @@ QString *qstring_from_substr(const char *str, size_t st= art, size_t end) { QString *qstring; =20 - assert(start <=3D end + 1); + assert(start <=3D end); =20 qstring =3D g_malloc(sizeof(*qstring)); qobject_init(QOBJECT(qstring), QTYPE_QSTRING); =20 - qstring->length =3D end - start + 1; + qstring->length =3D end - start; qstring->capacity =3D qstring->length; =20 assert(qstring->capacity < SIZE_MAX); @@ -64,7 +64,7 @@ QString *qstring_from_substr(const char *str, size_t star= t, size_t end) */ QString *qstring_from_str(const char *str) { - return qstring_from_substr(str, 0, strlen(str) - 1); + return qstring_from_substr(str, 0, strlen(str)); } =20 static void capacity_increase(QString *qstring, size_t len) diff --git a/tests/check-qobject.c b/tests/check-qobject.c index 16ccbde82c..593c3a0618 100644 --- a/tests/check-qobject.c +++ b/tests/check-qobject.c @@ -154,7 +154,7 @@ static void qobject_is_equal_string_test(void) str_case =3D qstring_from_str("Foo"); =20 /* Should yield "foo" */ - str_built =3D qstring_from_substr("form", 0, 1); + str_built =3D qstring_from_substr("form", 0, 2); qstring_append_chr(str_built, 'o'); =20 check_unequal(str_base, str_whitespace_0, str_whitespace_1, diff --git a/tests/check-qstring.c b/tests/check-qstring.c index f11a7a8605..2d079921e3 100644 --- a/tests/check-qstring.c +++ b/tests/check-qstring.c @@ -66,7 +66,7 @@ static void qstring_from_substr_test(void) { QString *qs; =20 - qs =3D qstring_from_substr("virtualization", 3, 9); + qs =3D qstring_from_substr("virtualization", 3, 10); g_assert(qs !=3D NULL); g_assert(strcmp(qstring_get_str(qs), "tualiza") =3D=3D 0); =20 --=20 2.17.1