This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Interesting discovery in the C library that Cygwin uses
On 2010-07-08 23:34Z, Gregg Levine wrote:
> I made this discovery whilst building the urjtag program from its SVN trunk:
> make[3]: Entering directory `/usr/local/urjtag/urjtag/trunk/urjtag/src/tap'
> CC tap.lo
> CC register.lo
> CC state.lo
> CC chain.lo
> CC detect.lo
> detect.c: In function `find_record':
> detect.c:89: warning: array subscript has type `char'
http://urjtag.svn.sourceforge.net/viewvc/urjtag/trunk/urjtag/src/tap/detect.c?annotate=1799
char *p;
...
while (*p && isspace (*p))
The problem is that 'char' can be signed, and a signed quantity can
be negative. But values passed to <ctype.h> functions like isspace()
have to be in the (nonnegative) range of an unsigned char (or be
equal to EOF); otherwise, the behavior is undefined. Consider using
unsigned char *p;
instead of
char *p;
in the example above.
Here's some discussion:
https://www.securecoding.cert.org/confluence/display/seccode/STR37-C.+Arguments+to+character+handling+functions+must+be+representable+as+an+unsigned+char
http://old.nabble.com/warnings-from-use-of-ctype.h-methods-td27865685.html
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple