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

Re: [PATCH nd/wildmatch] Correct Git's version of isprint and isspace

From
JSJan H. Schönherr <schnhrr@cs.tu-berlin.de>
Date
Nov 13, 2012, 18:58 UTC
Message-ID
<50A29866.1070700@cs.tu-berlin.de>
In-Reply-To
<1352803572-14547-1-git-send-email-pclouds@gmail.com>
Hi.
Am 13.11.2012 11:46, schrieb Nguyễn Thái Ngọc Duy:
Show 33 quoted lines
> Git's ispace does not include 11 and 12. Git's isprint includes
> control space characters (10-13). According to glibc-2.14.1 on C
> locale on Linux, this is wrong. This patch fixes it.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  I wrote a small C program to compare the result of all is* functions
>  that Git replaces against the libc version. These are the only ones that
>  differ. Which matches what Jan Schönherr commented.
> 
>  ctype.c           |  6 +++---
>  git-compat-util.h | 11 ++++++-----
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/ctype.c b/ctype.c
> index 0bfebb4..71311a3 100644
> --- a/ctype.c
> +++ b/ctype.c
> @@ -14,11 +14,11 @@ enum {
>  	P = GIT_PATHSPEC_MAGIC, /* other non-alnum, except for ] and } */
>  	X = GIT_CNTRL,
>  	U = GIT_PUNCT,
> -	Z = GIT_CNTRL | GIT_SPACE
> +	Z = GIT_CNTRL_SPACE
>  };
>  
> -const unsigned char sane_ctype[256] = {
> -	X, X, X, X, X, X, X, X, X, Z, Z, X, X, Z, X, X,		/*   0.. 15 */
> +const unsigned int sane_ctype[256] = {
> +	X, X, X, X, X, X, X, X, X, Z, Z, Z, Z, Z, X, X,		/*   0.. 15 */
>  	X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X,		/*  16.. 31 */
>  	S, P, P, P, R, P, P, P, R, R, G, R, P, P, R, P,		/*  32.. 47 */
>  	D, D, D, D, D, D, D, D, D, D, P, P, P, P, P, G,		/*  48.. 63 */

An alternative to switching from 1-byte to 4-byte values (don't we have a 2-byte datatype?), would be to free up GIT_CNTRL and simply do:

#define iscntrl(x) ((x) < 0x20)
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 02f48f6..4ed3f94 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
[...]
Show 7 quoted lines
> @@ -483,9 +483,10 @@ extern const unsigned char sane_ctype[256];
>  #define GIT_PATHSPEC_MAGIC 0x20
>  #define GIT_CNTRL 0x40
>  #define GIT_PUNCT 0x80
> -#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
> +#define GIT_SPACE 0x100
> +#define sane_istest(x,mask) ((sane_ctype[(unsigned int)(x)] & (mask)) != 0)

That should better be left "(unsigned char)"? We might access values after the array otherwise.

(That said, it wasn't really correct before either, when there really is a possibility that x >= 0x100.)

Regards Jan

PS: It looks like my isprint() version was given precedence over your
isprint() version during the merge into next. That should also be sorted out,
but I've no idea which one is actually better: two comparisons versus one
cache lookup and a bitop... (though my guess is that comparisons are cheaper,
but then we should also convert isdigit()...)
Previous: Nguyễn Thái Ngọc DuyNext: René Scharfe
Message 13 of 37 in “nd/wildmatch”
  1. 00/12 nd/wildmatchNguyễn Thái Ngọc Duy, Oct 14, 2012
  2. 01/12 ctype: make sane_ctype[] const arrayNguyễn Thái Ngọc Duy, Oct 14, 2012
  3. 02/12 ctype: support iscntrl, ispunct, isxdigit and isprintNguyễn Thái Ngọc Duy, Oct 14, 2012
  4. Junio C HamanoOct 14, 2012
  5. Nguyen Thai Ngoc DuyOct 14, 2012
  6. René ScharfeOct 14, 2012
  7. Nguyen Thai Ngoc DuyOct 14, 2012
  8. René ScharfeOct 14, 2012
  9. Nguyen Thai Ngoc DuyOct 14, 2012
  10. Jan H. SchönherrOct 17, 2012
  11. Nguyen Thai Ngoc DuyOct 17, 2012
  12. Correct Git's version of isprint and isspaceNguyễn Thái Ngọc Duy, Nov 13, 2012
  13. Jan H. SchönherrNov 13, 2012
  14. René ScharfeNov 13, 2012
  15. René ScharfeNov 13, 2012
  16. Linus TorvaldsNov 13, 2012
  17. Linus TorvaldsNov 13, 2012
  18. René ScharfeNov 14, 2012
  19. Johannes SixtNov 13, 2012
  20. wildmatch: correct isprint and isspaceNguyễn Thái Ngọc Duy, Nov 15, 2012
  21. Jan H. SchönherrNov 15, 2012
  22. Nguyen Thai Ngoc DuyNov 16, 2012
  23. 03/12 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Oct 14, 2012
  24. 04/12 wildmatch: remove unnecessary functionsNguyễn Thái Ngọc Duy, Oct 14, 2012
  25. Junio C HamanoOct 14, 2012
  26. Nguyen Thai Ngoc DuyOct 14, 2012
  27. 05/12 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Oct 14, 2012
  28. Junio C HamanoOct 14, 2012
  29. Torsten BögershausenOct 14, 2012
  30. 06/12 t3070: disable unreliable fnmatch testsNguyễn Thái Ngọc Duy, Oct 14, 2012
  31. 07/12 wildmatch: make wildmatch's return value compatible with fnmatchNguyễn Thái Ngọc Duy, Oct 14, 2012
  32. Junio C HamanoOct 14, 2012
  33. 08/12 wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Oct 14, 2012
  34. 09/12 wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Oct 14, 2012
  35. 10/12 wildmatch: adjust "**" behaviorNguyễn Thái Ngọc Duy, Oct 14, 2012
  36. 11/12 wildmatch: make /**/ match zero or more directoriesNguyễn Thái Ngọc Duy, Oct 14, 2012
  37. 12/12 Support "**" wildcard in .gitignore and .gitattributesNguyễn Thái Ngọc Duy, Oct 14, 2012

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.