[MPlayer-dev-eng] ctype.h functions on win32

Rich Felker dalias at aerifal.cx
Sun Oct 14 15:11:07 CEST 2007


On Sun, Oct 14, 2007 at 09:15:45AM +0200, Reimar Döffinger wrote:
> > > Check if something like
> > > #define isspace(c) ((c) != EOF && isspace((unsigned char)(c)))
> > > works.
> > 
> > This is unnecessary. The issue is NOT msvc crashing when -1 is passed.
> > The issue is msvc crashing when signed char values in the range -128
> > to -2 are passed. The relevant arrays/pointers simply need to be
> > changed to unsigned char.
> 
> Well, c might be an int returned from fgetc.

Any value returned by fgetc is automatically valid as an argument to
isspace or any of the is*() functions. RTFM!!!!!!!!!!!!!!!

> And I disagree about making then unsigned char, that will add hundreds
> of (admittedly stupid) gcc warnings about signedness not matching in
> pointer arguments.
> I also do not like using unsigned char because the "normal" type for
> strings is still char *, and changing it only in a few places IMO is
> clearly a hack.

If you are processing the bytes of a string, they need to be
interpreted as unsigned. You can either change the type of the pointer
or cast them as you read them. I don't care. But pretending that
reading bytes from a char * and using them directly is valid is
stupid.

Alternatively, drop the use of is*() functions entirely (their
semantics are incorrect) and use trivial ascii-specific
macros/functions in their place.

> And if you think char should be unsigned I think there is a gcc compiler
> flag to change that without changing the code (might have interesting
> side-effects if some other code incorrectly assumes char to be signed).

Using gcc compiler flags to redefine the language is NOT ACCEPTABLE!!
There is clearly a dependency on an implementation-defined behavior,
the signedness of char, and specifying "we only support
implementations where char is unsigned" is not acceptable regardless
of whether the popular implementation has such a mode switch.

Rich



More information about the MPlayer-dev-eng mailing list