block-qdict: Simplify qdict_is_list() some

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
master
Markus Armbruster 2018-06-14 21:14:38 +02:00 committed by Kevin Wolf
parent 3692b5d768
commit c78b8cfbfd
1 changed files with 11 additions and 16 deletions

View File

@ -317,27 +317,22 @@ static int qdict_is_list(QDict *maybe_list, Error **errp)
for (ent = qdict_first(maybe_list); ent != NULL; for (ent = qdict_first(maybe_list); ent != NULL;
ent = qdict_next(maybe_list, ent)) { ent = qdict_next(maybe_list, ent)) {
int is_index = !qemu_strtoi64(ent->key, NULL, 10, &val);
if (qemu_strtoi64(ent->key, NULL, 10, &val) == 0) {
if (is_list == -1) { if (is_list == -1) {
is_list = 1; is_list = is_index;
} else if (!is_list) { }
error_setg(errp,
"Cannot mix list and non-list keys"); if (is_index != is_list) {
error_setg(errp, "Cannot mix list and non-list keys");
return -1; return -1;
} }
if (is_index) {
len++; len++;
if (val > max) { if (val > max) {
max = val; max = val;
} }
} else {
if (is_list == -1) {
is_list = 0;
} else if (is_list) {
error_setg(errp,
"Cannot mix list and non-list keys");
return -1;
}
} }
} }