Hi Henrik,
At 21.18 27/03/2007, Henrik Nordstrom wrote:
>tis 2007-03-27 klockan 13:16 +0200 skrev Guido Serassio:
>
> > >What was the warnings you fixed with these casts? I suspect you only
> > >silenced a valid warning here without fixing the cause..
> >
> > Exactly these:
> >
> > http://www.squid-cache.org/mail-archive/squid-dev/200702/0128.html
>
>Ok, what I thought..
>
>the warning says that isspace(x) is implemented as a macro translating
>into something like isspace_array[x]
>
>with x being a char the compiler warns on array references as the
>standard does not define if a char is signed or unsigned and thus the
>results may differ from platform to platform.
>
>What the warning really should have said is "watch out here, there is a
>unqualified char type passed to a ctype function, you most likely want
>to change or cast this into unsigned char".
>
>if you cast into int the compiler doesn't warn on this as int is the
>correct type and it's always valid to cast char into int, but the code
>is still just as broken as before. If x is 0x80 the code becomes
>isspace_array[-128] which is far outside the allowed range for isspace.
>(assuming char signed by default, which is very common).
>
>isspace is only valid on unsigned char values, and as a special case EOF
>(usually -1). Any other use of ctype functions is outside
>specifications. Luckily many implementations handle this correctly by
>allowing ctype queries in the range -128 - +255 accounting both for
>signed and unsigned char, but it can not be guaranteed.
It's almost clear, but I'm just a little confused on the logical side
of the things: use an int argument to check for an unsigned char.
Really a confusing prototype .....
Henrik, now I don't have a CVS access, if it's not a problem I will
fix this in few days.
Regards
Guido
-
========================================================
Guido Serassio
Acme Consulting S.r.l. - Microsoft Certified Partner
Via Lucia Savarino, 1 10098 - Rivoli (TO) - ITALY
Tel. : +39.011.9530135 Fax. : +39.011.9781115
Email: guido.serassio@acmeconsulting.it
WWW: http://www.acmeconsulting.it/
Received on Tue Mar 27 2007 - 14:10:12 MDT
This archive was generated by hypermail pre-2.1.9 : Sun Apr 01 2007 - 12:00:01 MDT