[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnupg-devel
Subject:    Re: [Patch] Wrong usage of ctype functions
From:       Werner Koch <wk () gnupg ! org>
Date:       2003-06-07 18:54:36
[Download RAW message or body]

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.


Shalom-Salam,

   Werner

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


_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic