[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nmh-workers] char args passed to isalpha() et al.
From: |
Peter Maydell |
Subject: |
Re: [Nmh-workers] char args passed to isalpha() et al. |
Date: |
Wed, 11 Apr 2007 10:44:09 +0100 |
Joel Reicher wrote:
>Functions such as isalpha() take an int argument, but in lots of places
>the nmh code passes a char (actually a dereferenced char pointer).
>
>I imagine on many platforms this isn't an issue, but on mine (NetBSD 3.1)
>these functions are macros that expand to array lookups, and gcc gives
>lots of warnings like
>
>mhbuildsbr.c:690: warning: subscript has type `char'
>
>as a result.
>
>The warnings are annoying, and make it hard to spot other warnings.
>I have three choices. One is to use -Wno-char-subscripts. I don't like
>this option. Another is to explicitly cast to int everywhere. That
>seems to be the most harmless. The third is to accept that this might be
>an oddity of NetBSD and let it go.
>
>Does anybody mind if I put the int casts in? Should I go with a different
>option? Have I missed something?
I'm not sure, but I think that the problem is to do with 'signed'
vs 'unsigned' char. isalpha() et al want a value which is an unsigned
char. If on some platform char is signed and we do something like:
isalpha((int)*p) /* p is a 'char *' */
and whatever char p points to is in the -ve range then isalpha is
entitled to blow up.
So the cleanest fix is probably to make sure that we're using 'unsigned
char *' in all the places where it matters. The simplest fix is to use
isalpha((unsigned char)*p)
(ie cast to unsigned char at point of use).
Casting to int will kill the warning but leave the problem in place, so
it's the wrong approach.
-- PMM