diff options
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r-- | mysys/my_getopt.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index e4b199dab84..1c5bf0b6b1c 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -603,18 +603,24 @@ static int setval(const struct my_option *opts, void *value, char *argument, }; break; case GET_ENUM: - if (((*(uint*)value)= - find_type(argument, opts->typelib, 2) - 1) == (uint)-1) { - /* Accept an integer representation of the enumerated item */ - char *endptr; - uint arg= (uint) strtol(argument, &endptr, 10); - if (*endptr || arg >= opts->typelib->count) + int type= find_type(argument, opts->typelib, 2); + if (type == 0) { - res= EXIT_ARGUMENT_INVALID; - goto ret; - }; - *(uint*)value= arg; + /* + Accept an integer representation of the enumerated item. + */ + char *endptr; + ulong arg= strtoul(argument, &endptr, 10); + if (*endptr || arg >= opts->typelib->count) + { + res= EXIT_ARGUMENT_INVALID; + goto ret; + } + *(ulong*)value= arg; + } + else + *(ulong*)value= type - 1; } break; case GET_SET: @@ -1010,7 +1016,7 @@ static void init_one_value(const struct my_option *option, void *variable, *((int*) variable)= (int) getopt_ll_limit_value((int) value, option, NULL); break; case GET_ENUM: - *((uint*) variable)= (uint) value; + *((ulong*) variable)= (ulong) value; break; case GET_UINT: *((uint*) variable)= (uint) getopt_ull_limit_value((uint) value, option, NULL); @@ -1286,7 +1292,7 @@ void my_print_variables(const struct my_option *options) printf("\n"); break; case GET_ENUM: - printf("%s\n", get_type(optp->typelib, *(uint*) value)); + printf("%s\n", get_type(optp->typelib, *(ulong*) value)); break; case GET_STR: case GET_STR_ALLOC: /* fall through */ |