From: Sven Berkvens-M. <sv...@dv...> - 2007-07-14 21:20:02
|
> Hi, Hello, > building dvdauthor 0.6.14 I see some warnings like this > > compat.c: In function `varied_open': > compat.c:43: warning: subscript has type `char' > > This happens on NetBSD/i386 and the only reason why it does not > occur on Linux is that Linux (I took a look at Debian) already does > the cast in its implementation of the ctype functions. I see that you're casting the char to int in your patch. Your Linux system does this for various reasons, but it's mostly to support old broken programs, as the comments in /usr/include/ctype.h explain. You should not be doing this, though. The values should be cast to an unsigned char first, then to int. Why? Because the isdigit (as do all other is*/to* functions/macros) expect a number from 0 upto and including 255 as their (int) argument. Because char is signed on most systems, casting it to int immediately gives the functions an argument between -128 and 127 (inclusive), which they will use as an array index, and which will thus fail horribly for characters which have their most significant bit set. Casting the char to unsigned char first will cause the cast to int that comes second to produce a number in the correct range. The code should be something like: if (isdigit((int)(unsigned char)c[0])) { whatever(); } By the way, Linux handles the broken code correctly, because it allows both negative values and (high) positive values. Other systems are not as relaxed about this, and do not accept broken negative numbers. > ciao > Klaus -- With kind regards, Sven Berkvens-Matthijsse sv...@dv... |