This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Interesting discovery in the C library that Cygwin uses


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Gregg Levine wrote, On 9.7.2010 1:34:
> Hello!
> 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'
> detect.c:96: warning: array subscript has type `char'
> detect.c:107: warning: array subscript has type `char'
> detect.c:125: warning: array subscript has type `char'
> detect.c:134: warning: array subscript has type `char'
> detect.c:150: warning: array subscript has type `char'
> make[3]: *** [detect.lo] Error 1
> make[3]: Leaving directory `/usr/local/urjtag/urjtag/trunk/urjtag/src/tap'
> make[2]: *** [all-recursive] Error 1
> make[2]: Leaving directory `/usr/local/urjtag/urjtag/trunk/urjtag/src'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory `/usr/local/urjtag/urjtag/trunk/urjtag'
> make: *** [all] Error 2
> The fix, temporarily as it happens was to add to the configure script
> this one: --disable-werror . The chap who suggested it also suggested
> that I complain here. It was described as  an isspace() has an issue,
> I won't use the term he used.
> 
> The code can be found at http://urjtag.sf.net as it happens.
> 
> Basically the program supporter there wants the people here for Cygwin
> to, ah, fix their C library. I'm not convinced that's necessary, but
> which C library is used here? And what could be fixed?
- From the ctype.h:

/* These macros are intentionally written in a manner that will trigger
   a gcc -Wall warning if the user mistakenly passes a 'char' instead
   of an int containing an 'unsigned char'.  Note that the sizeof will
   always be 1, which is what we want for mapping EOF to __ctype_ptr__[0];
   the use of a raw index inside the sizeof triggers the gcc warning if
   __c was of type char, and sizeof masks side effects of the extra __c.
   Meanwhile, the real index to __ctype_ptr__+1 must be cast to int,
   since isalpha(0x100000001LL) must equal isalpha(1), rather than being
   an out-of-bounds reference on a 64-bit machine.  */
#define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

The interesting part: "These macros are intentionally written in a manner
that will trigger a gcc -Wall warning if the user mistakenly passes a 'char'
instead of an int containing an 'unsigned char'."

And this is from SUSv3: "The c argument is an int, the value of which the
application shall ensure is a character representable as an unsigned char or
equal to the value of the macro EOF. If the argument has any other value, the
behavior is undefined."

His code invokes undefined behaviour in case the char value is negative. The
warning is a good thing. He IMHO needs to fix his code.

- --
VH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFMNqTjr2CghdezFMkRCOKcAKDAjf97aQkCOMnChHklmF1h0P777gCfSfCo
7iVQdH4YBv9uPhyW0xNfAZo=
=smu3
-----END PGP SIGNATURE-----

--
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]