mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 13:38:26 +00: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. Backports commit ba891d68b4ff17faaea3d3a8bfd82af3eed0a134 from qemu
This commit is contained in:
parent
0a6e77ed42
commit
146aa2ba91
1 changed files with 3 additions and 3 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue