nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] char args passed to isalpha() et al.

2007-04-11 02:44:38
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
 


_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
http://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>