From 146aa2ba911a69126d0878277f085f21638d861e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 2 Aug 2018 21:24:17 -0400 Subject: [PATCH] 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. Backports commit ba891d68b4ff17faaea3d3a8bfd82af3eed0a134 from qemu --- qemu/qobject/qstring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu/qobject/qstring.c b/qemu/qobject/qstring.c index 1ad2bea4..95dfd503 100644 --- a/qemu/qobject/qstring.c +++ b/qemu/qobject/qstring.c @@ -41,13 +41,13 @@ 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); assert(qstring->capacity < SIZE_MAX); - qstring->length = end - start + 1; + qstring->length = end - start; qstring->capacity = qstring->length; qstring->string = g_malloc(qstring->capacity + 1); @@ -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)