delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/07/09/00:26:39

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,TW_RJ,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
X-Spam-Score: -100.273
Message-ID: <4C36A4E4.4070405@sh.cvut.cz>
Date: Fri, 09 Jul 2010 06:26:12 +0200
From: =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= <v DOT haisman AT sh DOT cvut DOT cz>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.4) Gecko/20100608 Thunderbird/3.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Interesting discovery in the C library that Cygwin uses
References: <AANLkTimvCA12jm3SNDaDs7yckO9GLwPd01P_U7mCqYju AT mail DOT gmail DOT com>
In-Reply-To: <AANLkTimvCA12jm3SNDaDs7yckO9GLwPd01P_U7mCqYju@mail.gmail.com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019