mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
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>
This commit is contained in:
parent
b65ab77b3a
commit
ba891d68b4
6 changed files with 8 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue