Skip to content

Commit

Permalink
qapi: Use qapi_enum_parse() in input_type_enum()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Markus Armbruster committed Sep 4, 2017
1 parent 9ae3307 commit 113e47a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions qapi/qapi-visit-core.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 113e47a

Please sign in to comment.