aboutsummaryrefslogtreecommitdiff
path: root/qobject/qstring.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2018-07-27 08:22:04 +0200
committerMarkus Armbruster <armbru@redhat.com>2018-07-28 09:09:58 +0200
commitba891d68b4ff17faaea3d3a8bfd82af3eed0a134 (patch)
treea60591188270f2ec5ade8eef780b26da5ddf0efd /qobject/qstring.c
parentb65ab77b3afadd7bb3051b341a5258ff7fb9d246 (diff)
downloadqemu-ba891d68b4ff17faaea3d3a8bfd82af3eed0a134.zip
qemu-ba891d68b4ff17faaea3d3a8bfd82af3eed0a134.tar.gz
qemu-ba891d68b4ff17faaea3d3a8bfd82af3eed0a134.tar.bz2
qstring: Move qstring_from_substr()'s @end one to the right
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 <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180727062204.10401-3-armbru@redhat.com>
Diffstat (limited to 'qobject/qstring.c')
-rw-r--r--qobject/qstring.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 1bb7784..0f1510e 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -41,12 +41,12 @@ QString *qstring_from_substr(const char *str, size_t start, size_t end)
{
QString *qstring;
- assert(start <= end + 1);
+ assert(start <= end);
qstring = g_malloc(sizeof(*qstring));
qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
- qstring->length = end - start + 1;
+ qstring->length = end - start;
qstring->capacity = qstring->length;
assert(qstring->capacity < SIZE_MAX);
@@ -64,7 +64,7 @@ QString *qstring_from_substr(const char *str, size_t start, 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));
}
static void capacity_increase(QString *qstring, size_t len)