Commit ba891d68 authored by Markus Armbruster's avatar Markus Armbruster
Browse files

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: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <20180727062204.10401-3-armbru@redhat.com>
parent b65ab77b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,

    if (c != filename) {
        QString *config_path;
        config_path = qstring_from_substr(filename, 0, c - filename - 1);
        config_path = qstring_from_substr(filename, 0, c - filename);
        qdict_put(options, "config", config_path);
    }

+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options,
    }

    /* TODO Implement option pass-through and set raw.filename here */
    raw_path = qstring_from_substr(filename, 0, c - filename - 1);
    raw_path = qstring_from_substr(filename, 0, c - filename);
    qdict_put(options, "x-raw", raw_path);

    /* TODO Allow multi-level nesting and set file.filename here */
+1 −1
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ static int nbd_parse_uri(const char *filename, QDict *options)
        /* strip braces from literal IPv6 address */
        if (uri->server[0] == '[') {
            host = qstring_from_substr(uri->server, 1,
                                       strlen(uri->server) - 2);
                                       strlen(uri->server) - 1);
        } else {
            host = qstring_from_str(uri->server);
        }
+3 −3
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ static void qobject_is_equal_string_test(void)
    str_case = qstring_from_str("Foo");

    /* Should yield "foo" */
    str_built = qstring_from_substr("form", 0, 1);
    str_built = qstring_from_substr("form", 0, 2);
    qstring_append_chr(str_built, 'o');

    check_unequal(str_base, str_whitespace_0, str_whitespace_1,
Loading