public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: Possibly buggy use of ctype.h macros.
Date: Wed, 3 Jan 2024 15:58:39 +0900	[thread overview]
Message-ID: <20240103155839.ecb5eddf00ccab39c882fe61@nifty.ne.jp> (raw)
In-Reply-To: <382d26d43e66b45eca9facdd8bb9063d@kylheku.com>

On Tue, 02 Jan 2024 19:59:57 -0800
Kaz Kylheku <kaz@kylheku.com> wrote:
> On 2024-01-02 16:11, Takashi Yano via Cygwin wrote:
> > Perhaps, the off-by-one is for EOF as you guess.
> 
> I doubt it. If EOF were out of range of char, it would have to be -129 or less,
> so that -127 would look even more wrong.
> 
> I see EOF is just -1. That value will also be produced by '\xFF', or "\xff"[0], etc.

In systems other than cygwin, ALLOW_NEGATIVE_CTYPE_INDEX might not
be set. In that case, 

 124 const char _ctype_[1 + 256] = {
 125         0,
 126         _CTYPE_DATA_0_127,
 127         _CTYPE_DATA_128_255
 128 };

is used for __CTYPE_PTR.

So, isalpha(EOF) reffers to 0 in line 125 via this trick.

  45 int
  46 isalpha (int c)
  47 {
  48         return(__CTYPE_PTR[c+1] & (_U|_L));
  49 }

In cygwin, both isalpha((char*)0xff) and isalpha(EOF) reffers to
_CTYPE_DATA_128_255[127] in line 89, while isalpha((unsigned char*)0xff)
reffers to _CTYPE_DATA_128_255[127] in line 91. 

  88 char _ctype_b[128 + 256] = {
  89         _CTYPE_DATA_128_255,
  90         _CTYPE_DATA_0_127,
  91         _CTYPE_DATA_128_255
  92 };

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

      reply	other threads:[~2024-01-03  6:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 22:18 Kaz Kylheku
2024-01-02 23:25 ` Takashi Yano
2024-01-02 23:56   ` Kaz Kylheku
2024-01-03  0:11     ` Takashi Yano
2024-01-03  3:59       ` Kaz Kylheku
2024-01-03  6:58         ` Takashi Yano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103155839.ecb5eddf00ccab39c882fe61@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).