signed vs unsigned pointer warning

Dave Korn
Fri Oct 8 13:32:00 GMT 2004

> -----Original Message-----
> From: Nick Ing-Simmons [] 
> Sent: 08 October 2004 14:06

> >This is a real typical bug.  Just recently a bug was found in
> >curl-library, quite a popular little library, which calls
> >isspace(char).  The bug was missed for a long time, as it is only
> >triggered with characters with the MSB set, which do not occur often
> >in HTTP headers.
> I am reasnably sure that on old SunOS4 systems passing signed char 
> to isxxx() was normal and worked. The lookup tables where defined
> in such a way that 128 or so entries before the normal table 
> replicated 
> the 2nd half.
> Snag is it is hard to define such arrays in C.

  Well, you don't, you just define a "type * const" pointer to the 128'th
entry of the real underlying, e.g. instead of saying

unsigned char isXXX_flags_array[256]

you say

static unsigned char __isXXX_flags_array[256];
unsigned char * const isXXX_flags_array = &__is_flags_array[128];

  Or at any rate, I use that idiom quite a lot.

Can't think of a witty .sigline today....

More information about the Gcc mailing list