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

Re: [PATCH 1/5] git-compat-util: add isblank() and isgraph()

From
Masahiro Yamada <masahiroy@kernel.org>
Date
Feb 10, 2023, 19:25 UTC
Message-ID
<CAK7LNAQM6tGmZvy9jVWy099dsOte_=P-Ro3CuAqAc5akiakyoQ@mail.gmail.com>
In-Reply-To
<xmqqo7q1ibek.fsf@gitster.g>
On Sat, Feb 11, 2023 at 4:11 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
>
> Masahiro Yamada <masahiroy@kernel.org> writes:
>
> > Use them with care because they are not robust against the pointer
> > increment, like isblank(*s++).
> >
> > The same issue already exists for isspace().
>
> Does it?
Sorry, I meant:
 "The same issue already exists for isprint()"
   #define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
is not robust against pointer increment.
Show 23 quoted lines
>
> >  #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
> >  #define isascii(x) (((x) & ~0x7f) == 0)
> >  #define isspace(x) sane_istest(x,GIT_SPACE)
>
> sane_istest() evaluates x and mask only once, and isspace evaluates
> x only once, no?
>
>         isspace(*x++)
>         ->
>         sane_istest(*x++,GIT_SPACE)
>         ->
>         ((sane_ctype[(unsigned char)(*x++)] & GIT_SPACE) != 0)
>
> > +#define isblank(x) (isspace(x) || (x) == '\t')
> > +#define isgraph(x) (isprint(x) && !isspace(x))
>
> Given that all the other tests are implemented with just picking an
> integer from the table and checking bit(s), the above two look
> somewhat out of place.  The fact, as you noted, that they cannot be
> used safely does not help, either.
>
>

At first, I hesitated to move these to git-compat-util.h for this reason, but I noticed isprint() was in the same situation.

So, I decided to go.
-- 
Best Regards
Masahiro Yamada
Previous: Junio C HamanoNext: René Scharfe
Message 6 of 17 in “Clean up wildmatch.c”
  1. 0/5 Clean up wildmatch.cMasahiro Yamada, Feb 10, 2023
  2. 1/5 git-compat-util: add isblank() and isgraph()Masahiro Yamada, Feb 10, 2023
  3. Ævar Arnfjörð BjarmasonFeb 10, 2023
  4. Masahiro YamadaFeb 10, 2023
  5. Junio C HamanoFeb 10, 2023
  6. Masahiro YamadaFeb 10, 2023
  7. René ScharfeFeb 10, 2023
  8. Masahiro YamadaFeb 11, 2023
  9. René ScharfeFeb 11, 2023
  10. René ScharfeFeb 11, 2023
  11. 2/5 wildmatch: remove IS*() macrosMasahiro Yamada, Feb 10, 2023
  12. 3/5 wildmatch: remove NEGATE_CLASS and NEGATE_CLASS2 macrosMasahiro Yamada, Feb 10, 2023
  13. Ævar Arnfjörð BjarmasonFeb 10, 2023
  14. Masahiro YamadaFeb 10, 2023
  15. 5/5 wildmatch: more cleanups after killing ucharMasahiro Yamada, Feb 10, 2023
  16. 4/5 wildmatch: use char instead of ucharMasahiro Yamada, Feb 10, 2023
  17. Ævar Arnfjörð BjarmasonFeb 10, 2023

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.