char array subscript in ctype

Vincent Lefevre vincent at vinc17.org
Sun Dec 30 15:50:37 PST 2001


On Sun, Dec 30, 2001 at 18:34:26 +0000, Peter Naulls wrote:
> I'm not sure that's a valid argument.  isspace and friends are almost
> always used in the context of unqualified chars (unsigned on ARM, signed
> on x86).   Futhermore, the specification for these functions says that
> the integer passed is interpreted as an unsigned char (or EOF).  The
> cast to unsigned int ensures this.

No, if you cast the argument to unsigned int in the macro definition,
EOF will become positive, which is incorrect. In __ctype[c], the EOF
index is (in this implementation) -1. With the cast, the wrong byte
will be read.

> That aside, the real point is that the library headers cause a warning,
> which they really shouldn't.

They should, as using a char may be an error. For instance, in Mutt,
there was such an error when accented characters (signed under some
implementations) were used. The bug was in Mutt, not in the compiler's
headers. Since then, casts have been added in Mutt.

-- 
Vincent Lefèvre <vincent at vinc17.org> - Web: <http://www.vinc17.org/> - 100%
validated HTML - Acorn Risc PC, Yellow Pig 17, Championnat International des
Jeux Mathématiques et Logiques, TETRHEX, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA



More information about the gcc mailing list