git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATH/RFC] parse-options: report invalid UTF-8 switches

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Feb 11, 2013, 13:43 UTC
Message-ID
<vpqobfr9da7.fsf@grenoble-inp.fr>
In-Reply-To
<1360589687-9233-1-git-send-email-kusmabite@gmail.com>
Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 21 quoted lines
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -3,6 +3,7 @@
>  #include "cache.h"
>  #include "commit.h"
>  #include "color.h"
> +#include "utf8.h"
>  
>  static int parse_options_usage(struct parse_opt_ctx_t *ctx,
>  			       const char * const *usagestr,
> @@ -462,7 +463,9 @@ int parse_options(int argc, const char **argv, const char *prefix,
>  		if (ctx.argv[0][1] == '-') {
>  			error("unknown option `%s'", ctx.argv[0] + 2);
>  		} else {
> -			error("unknown switch `%c'", *ctx.opt);
> +			const char *next = ctx.opt;
> +			utf8_width(&next, NULL);
> +			error("unknown switch `%.*s'", (int)(next - ctx.opt), ctx.opt);
>  		}
>  		usage_with_options(usagestr, options);
>  	}

You should be careful with the case where the user has a non-UTF8 environment, and entered a non-ascii sequence. I can see two cases:

1) The non-ascii sequence is valid UTF-8, then I guess your patch would
   show two characters instead of one. Not really correct, but not really
   serious either.
2) The non-ascii sequence is NOT valid UTF-8, then if I read correctly
   (I didn't test) utf8_width would set next to NULL, and then you are
   in big trouble.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 2 of 13 in “[PATH/RFC] parse-options: report invalid UTF-8 switches”
  1. Erik Faye-LundFeb 11, 2013
  2. Matthieu MoyFeb 11, 2013
  3. Erik Faye-LundFeb 11, 2013
  4. Matthieu MoyFeb 11, 2013
  5. Erik Faye-LundFeb 11, 2013
  6. Torsten BögershausenFeb 11, 2013
  7. Erik Faye-LundFeb 11, 2013
  8. Torsten BögershausenFeb 11, 2013
  9. Junio C HamanoFeb 11, 2013
  10. Erik Faye-LundFeb 11, 2013
  11. Jeff KingFeb 11, 2013
  12. Erik Faye-LundFeb 11, 2013
  13. Junio C HamanoFeb 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.