[Patch] Wrong usage of ctype functions

Werner Koch wk at gnupg.org
Sat Jun 7 21:51:02 CEST 2003

On Fri, 6 Jun 2003 18:31:37 +0200, Christian Biere said:

> macro EOF". As "char" is a synonym for "signed char" changed on
> several architectures the implicit cast to "int" will gain negative
> values for many characters.

> -	if( !*s || (*s & 0x80) || (!isgraph(*s) && !isspace(*s)) )
> +	if( !*s || (*s & 0x80) ||

But not here.  We already checked that that it is an ascii character;
i.e. one which won't yield a negative value.  I am very well ware of
the problem but you compiler warnings are incorrect.  

I agree that isascii () would be a cleaner solution than explicit bit
testing.  isascii () is defined vor all integer values and actually
pretty simple.  I am using that in newer code.

>      for( s++; *s ; s++ ) {
> -	if( iscntrl(*s) ) {
> +	if( iscntrl((unsigned char) *s) ) {
>  	    log_error(_("a notation value must not use "

Here you are right, however a better fix is to use:

	if ((*s & 0x80))
          highbit = 1;
	else if (iscntrl(*s)) {

> -    if(string[i]&0x80 || iscntrl(string[i]))
> +    if(string[i]&0x80 || iscntrl((unsigned char) string[i]))
>        break;

See above. 

Many thanks for pointing out all the other buggy uses.  I have fixed
them with my simple testing macros spacep, digitp and hexdigitp which
are not subject to localization - we are actually testing only for
ascii values.



Werner Koch                                      <wk at gnupg.org>
The GnuPG Experts                                http://g10code.com
Free Software Foundation Europe	                 http://fsfeurope.org

More information about the Gnupg-devel mailing list