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
This commit is contained in:
Markus Armbruster 2018-08-02 21:24:17 -04:00 committed by Lioncash
parent 0a6e77ed42
commit 146aa2ba91
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -41,13 +41,13 @@ QString *qstring_from_substr(const char *str, size_t start, size_t end)
{ {
QString *qstring; QString *qstring;
assert(start <= end + 1); assert(start <= end);
qstring = g_malloc(sizeof(*qstring)); qstring = g_malloc(sizeof(*qstring));
qobject_init(QOBJECT(qstring), QTYPE_QSTRING); qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
assert(qstring->capacity < SIZE_MAX); assert(qstring->capacity < SIZE_MAX);
qstring->length = end - start + 1; qstring->length = end - start;
qstring->capacity = qstring->length; qstring->capacity = qstring->length;
qstring->string = g_malloc(qstring->capacity + 1); 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) 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) static void capacity_increase(QString *qstring, size_t len)