public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: signed vs unsigned pointer warning
@ 2004-09-22 16:43 Morten Welinder
  2004-09-22 17:17 ` Paul Koning
  2004-09-22 17:20 ` Dave Korn
  0 siblings, 2 replies; 31+ messages in thread
From: Morten Welinder @ 2004-09-22 16:43 UTC (permalink / raw)
  To: gcc; +Cc: dk


Dave Korn writes:

> Until you try indexing an array with an 8-bit high ASCII char, of course.
> Then things become radically different.  I've known buggy ctype
> implementations that have failed on this (ASCII > 127 being signed negative
> and the ctype function accidentally indexing memory space before an array
> full of ctype result flags).

[/me gathers soapbox]

I bet you have.  In fact *ALL* ctype implementations will fail.[*]
That includes glibc

What glibc does is to *mostly* work around buggy programs that send
(explicitly or implicitly) signed characters to, say, isprint.  It does
not always work, though, so glibc really did you a disservice.  It is
really hard to get people to fix their programs.

It does not work for (signed char)-1 if EOF==-1.  It cannot work as two
different results are required for the same argument value.

Solaris does the array[arg] thing you speak about.  It isn't buggy.  The
caller is, and, IMHO the standard is.

Morten


[*] Assuming (char)EOF==EOF, which it will be with signed characters and
EOF==-1.

^ permalink raw reply	[flat|nested] 31+ messages in thread
* signed vs unsigned pointer warning
@ 2004-09-21 20:52 Richard Henderson
  2004-09-21 22:36 ` Linus Torvalds
  0 siblings, 1 reply; 31+ messages in thread
From: Richard Henderson @ 2004-09-21 20:52 UTC (permalink / raw)
  To: gcc; +Cc: torvalds

[ Forwarded from the thread beginning at
  http://marc.theaimsgroup.com/?l=linux-sparse&m=109577992701909&w=2
]

On Tue, Sep 21, 2004 at 09:49:43AM -0700, Linus Torvalds wrote:
> In fact, even the "explicit sign" differences are a bit questionable. The 
> xdr4 code does something like this:
> 
> 	s64	len, start, end;
> 	...
> 	p = xdr_decode_hyper(p, &start);
> 	p = xdr_decode_hyper(p, &len);
> 	..
> 
> and both of these generate warnings, because xdr_decode_hyper() looks like
> 
> 	static inline u32 *
> 	xdr_decode_hyper(u32 *p, __u64 *valp)
> 
> but the fact is, it obviously works fine to return both u64 and s64
> values, and forcing the caller to use one over the other is just not that
> sensible.

Maybe.  Or maybe it's a bug that the caller typo'd s64 instead of u64,
and (start < end) will mistakenly compare false when end gets large.

> ... and duplicating the function to do the same thing also seems 
> totally idiotic.

I don't agree.  If signed vs unsigned really isn't important, because
xdr_decode_hyper does no range checking, yadda yadda, then

	static inline u32 *
	xdr_decode_hyper_s(u32 *p, s64 *valp)
	{
	  return xdr_decode_hyper (p, (u64 *) valp));
	}

does not seem too much to ask.

> Richard, are you sure that the gcc team has thought this through wrt
> gcc-4.0, or is this just another total disaster like adding
> "-Wsign-compare" to the default flags in gcc-3.0?

I think we're on more solid ground here than -Wsign-compare, because
the types "int *" and "unsigned int *" are not compatible [c99 6.2.7].
IANAL, but we could be within our rights to reject the program entirely
[c99 6.5.16.1].

I am finding it somewhat annoying that there's no -W switch to turn it
off though, since there are three include/linux/ headers that now prevent
me from using -Werror under arch/alpha/.


r~

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2004-10-11  9:53 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 16:43 signed vs unsigned pointer warning Morten Welinder
2004-09-22 17:17 ` Paul Koning
2004-09-22 17:27   ` Morten Welinder
2004-09-22 17:49     ` Dave Korn
2004-09-22 17:20 ` Dave Korn
2004-09-23  1:31   ` Andreas Schwab
2004-09-23 12:29     ` Dave Korn
2004-09-23 18:57       ` Joe Buck
2004-09-23 19:38         ` Dave Korn
2004-09-27  2:04   ` Jamie Lokier
2004-10-08 13:29     ` Nick Ing-Simmons
2004-10-08 13:32       ` Dave Korn
2004-10-08 17:20       ` Joe Buck
2004-10-08 17:28         ` Paul Jarc
2004-10-08 17:59           ` Joe Buck
2004-10-08 18:15             ` Dave Korn
2004-10-08 18:22               ` Joe Buck
2004-10-08 18:24             ` Jamie Lokier
2004-10-08 19:57             ` Paul Jarc
2004-10-09  7:05               ` Jamie Lokier
2004-10-09  8:48                 ` Paul Jarc
2004-10-11 16:34                   ` Richard Earnshaw
2004-10-08 18:57         ` Morten Welinder
2004-10-08 20:59           ` Matthias B.
2004-10-08 22:34             ` Paul Koning
2004-10-10  2:03               ` Matthias B.
2004-10-09  1:39             ` Andreas Schwab
2004-10-11  0:11           ` Kai Henningsen
  -- strict thread matches above, loose matches on Subject: below --
2004-09-21 20:52 Richard Henderson
2004-09-21 22:36 ` Linus Torvalds
2004-09-22 14:35   ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).