aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-08-24 10:46:05 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-09-04 13:09:13 +0200
commit113e47ae6dc45b08e732dd5fa85abe71b764f5ae (patch)
treefff232e2b895ff91cb8e2cdaa0df80cf113e436c
parent9ae33079c2061d73c88dbe2dd79373dedc50f693 (diff)
qapi: Use qapi_enum_parse() in input_type_enum()
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-11-git-send-email-armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
-rw-r--r--qapi/qapi-visit-core.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index ed6d2af462..ec83ff68f9 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -14,6 +14,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "qapi/util.h"
#include "qemu-common.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qerror.h"
@@ -353,7 +354,7 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
const char *const strings[], Error **errp)
{
Error *local_err = NULL;
- int64_t value = 0;
+ int64_t value;
char *enum_str;
visit_type_str(v, name, &enum_str, &local_err);
@@ -362,14 +363,8 @@ static void input_type_enum(Visitor *v, const char *name, int *obj,
return;
}
- while (strings[value] != NULL) {
- if (strcmp(strings[value], enum_str) == 0) {
- break;
- }
- value++;
- }
-
- if (strings[value] == NULL) {
+ value = qapi_enum_parse(strings, enum_str, -1, NULL);
+ if (value < 0) {
error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
g_free(enum_str);
return;