[Spice-devel] [PATCH] client/cmd_line_parser: fix wrong reporting of bad argument in --bla=val case

Alon Levy alevy at redhat.com
Thu Jan 6 03:49:05 PST 2011


Had a debug print in there, removed, see v2 later.
NACK.


On Thu, Jan 06, 2011 at 01:15:26PM +0200, Alon Levy wrote:
> We use get_opt_long, which allows non ambiguous abbreviations, but
> since we didn't like that we have code that checks for abbreviations and
> issues an error. But that code only handled separate argument and key like:
> --bla value
> and didn't handle them in the same arguemnts, like:
> --bla=value
> This patch fixes that, and gives a slightly better error report (it still
> contains the =value part though)
> ---
>  client/cmd_line_parser.cpp |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/client/cmd_line_parser.cpp b/client/cmd_line_parser.cpp
> index 963250b..616ea81 100644
> --- a/client/cmd_line_parser.cpp
> +++ b/client/cmd_line_parser.cpp
> @@ -346,10 +346,15 @@ int CmdLineParser::get_option(char** val)
>          }
>  
>  #ifdef DISABLE_ABBREVIATE
> -        int name_pos = (opt_obj->type == REQUIRED_ARGUMENT) ? optind - 2 : optind - 1;
> +        int name_pos =
> +            (opt_obj->type == REQUIRED_ARGUMENT && optarg[-1] != '=')
> +            ? optind - 2
> +            : optind - 1;
> +        printf("opt_obj->type == %d, optarg[-1] == %c\n", opt_obj->type,
> +                optarg[-1]);
>          std::string cmd_name(_argv[name_pos] + 2);
>          if (cmd_name.find(opt_obj->name) != 0) {
> -            Platform::term_printf("%s: invalid option '--%s'\n", _argv[0], cmd_name.c_str());
> +            Platform::term_printf("%s: invalid abbreviated option '--%s'\n", _argv[0], cmd_name.c_str());
>              return OPTION_ERROR;
>          }
>  #endif
> -- 
> 1.7.3.4
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list