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

util/cutils: Change qemu_strtosz*() from int64_t to uint64_t



This will permit its use in parse_option_size().

Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com> (maintainer:X86)
Cc: Kevin Wolf <kwolf@redhat.com> (supporter:Block layer core)
Cc: Max Reitz <mreitz@redhat.com> (supporter:Block layer core)
Cc: qemu-block@nongnu.org (open list:Block layer core)
Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <1487708048-2131-24-git-send-email-armbru@redhat.com>
parent f17fd4fd
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1344,7 +1344,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
{
    const char *param = qdict_get_str(qdict, "parameter");
    const char *valuestr = qdict_get_str(qdict, "value");
    int64_t valuebw = 0;
    uint64_t valuebw = 0;
    long valueint = 0;
    Error *err = NULL;
    bool use_int_value = false;
@@ -1385,7 +1385,8 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
            case MIGRATION_PARAMETER_MAX_BANDWIDTH:
                p.has_max_bandwidth = true;
                ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
                if (ret < 0 || (size_t)valuebw != valuebw) {
                if (ret < 0 || valuebw > INT64_MAX
                    || (size_t)valuebw != valuebw) {
                    error_setg(&err, "Invalid size %s", valuestr);
                    goto cleanup;
                }
+1 −1
Original line number Diff line number Diff line
@@ -1268,7 +1268,7 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)
        s->legacy_size = 4 << 20; /* 4 MB default */
    } else {
        int ret;
        int64_t size;
        uint64_t size;

        ret = qemu_strtosz_MiB(s->sizearg, NULL, &size);
        if (ret < 0 || (size_t)size != size || !is_power_of_2(size)) {
+3 −3
Original line number Diff line number Diff line
@@ -139,9 +139,9 @@ int parse_uint(const char *s, unsigned long long *value, char **endptr,
               int base);
int parse_uint_full(const char *s, unsigned long long *value, int base);

int qemu_strtosz(const char *nptr, char **end, int64_t *result);
int qemu_strtosz_MiB(const char *nptr, char **end, int64_t *result);
int qemu_strtosz_metric(const char *nptr, char **end, int64_t *result);
int qemu_strtosz(const char *nptr, char **end, uint64_t *result);
int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);

#define K_BYTE     (1ULL << 10)
#define M_BYTE     (1ULL << 20)
+2 −2
Original line number Diff line number Diff line
@@ -2800,7 +2800,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
        case 'o':
            {
                int ret;
                int64_t val;
                uint64_t val;
                char *end;

                while (qemu_isspace(*p)) {
@@ -2813,7 +2813,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
                    }
                }
                ret = qemu_strtosz_MiB(p, &end, &val);
                if (ret < 0) {
                if (ret < 0 || val > INT64_MAX) {
                    monitor_printf(mon, "invalid size\n");
                    goto fail;
                }
+2 −4
Original line number Diff line number Diff line
@@ -481,7 +481,6 @@ opts_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp)
{
    OptsVisitor *ov = to_ov(v);
    const QemuOpt *opt;
    int64_t val;
    int err;

    opt = lookup_scalar(ov, name, errp);
@@ -489,14 +488,13 @@ opts_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp)
        return;
    }

    err = qemu_strtosz(opt->str ? opt->str : "", NULL, &val);
    err = qemu_strtosz(opt->str ? opt->str : "", NULL, obj);
    if (err < 0) {
        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
                   "a size value representible as a non-negative int64");
                   "a size value");
        return;
    }

    *obj = val;
    processed(ov, name);
}

Loading