[PATCH:libXt 4/6] Fix char vs. unsigned char warnings.

Thomas Dickey dickey at his.com
Thu Jun 27 01:23:06 PDT 2013


On Thu, Jun 27, 2013 at 08:33:02AM +0200, Thomas Klausner wrote:
> On Wed, Jun 26, 2013 at 08:55:35PM -0400, Thomas E. Dickey wrote:
> > On Tue, Jun 25, 2013 at 11:02:48PM +0200, Thomas Klausner wrote:
> > > ---
> > >  src/ResConfig.c | 4 ++--
> > >  src/TMparse.c   | 4 ++--
> > >  2 files changed, 4 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/src/ResConfig.c b/src/ResConfig.c
> > > index 152d9cf..5a7f6d2 100644
> > > --- a/src/ResConfig.c
> > > +++ b/src/ResConfig.c
> > > @@ -892,7 +892,7 @@ _XtResourceConfigurationEH (
> > >  	int		actual_format;
> > >  	unsigned long	nitems;
> > >  	unsigned long	leftover;
> > > -	unsigned char	*data = NULL;
> > > +	char		*data = NULL;
> > >  	unsigned long	resource_len;
> > >  	char		*data_ptr;
> > >  	char		*resource;
> > > @@ -952,7 +952,7 @@ _XtResourceConfigurationEH (
> > >  		pd->rcm_data, 0L, 8192L,
> > >  		TRUE, XA_STRING,
> > >  		&actual_type, &actual_format, &nitems, &leftover,
> > > -		&data ) == Success && actual_type == XA_STRING
> > > +		(unsigned char **)&data ) == Success && actual_type == XA_STRING
> > >  			   && actual_format == 8) {
> > 
> > One problem with casts is that they're telling the compiler to ignore its type-checking.
> > Casting an address like that happens to work - usually - but not always.
> 
> The problem is that the same variable is used in strtoul as first
> argument, which wants a 'const char *', and in XGetWindowProperty as
> 12th (if I didn't miscount), which wants an unsigned char **.

But taking the address of a pointer tends to get additional compiler warnings cautioning
about alignment, etc.  I would have probably put the cast on the strtoul call.  You might
want to compare results from these -

OPTS="-O -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wconversion
    -W
	-Wbad-function-cast
	-Wcast-align
	-Wcast-qual
	-Wmissing-declarations
	-Wnested-externs
	-Wpointer-arith
	-Wwrite-strings
	-ansi
	-pedantic
     "
gcc $OPTS "$@"

versus

OPTS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wconversion"
gcc $OPTS "$@"

-- 
Thomas E. Dickey <dickey at invisible-island.net>
http://invisible-island.net
ftp://invisible-island.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20130627/4b0b2873/attachment.pgp>


More information about the xorg-devel mailing list