Re: [IDEA+RFC] Possible solution for min()/max() war

From: Jamie Lokier (lk@tantalophile.demon.co.uk)
Date: Fri Aug 31 2001 - 11:27:54 EST


Roman Zippel wrote:
> > 3. Warning added to GCC for signed vs. unsigned comparisons
> > _regardless_ of type size. This would also catch erroneous
> > unsigned char vs. EOF checks in misuses of stdio.
>
> Do you know of such bug in the context of min()?

I don't know of an actual example. This one is made up:

       min (int, len, big_size)

Now if big_size has unsigned type, and does not fit in the range of int,
this expression will return the value of big_size cast to int, i.e. a
negative value. The suggested warning would catch this potential bug.

I don't know if it would warn for too many other things. Certainly, a
sizeof() exception (don't warn about signed comparison with sizeof()
result) is essential; perhaps too many other exceptions are required
too.

-- Jamie
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Aug 31 2001 - 21:00:34 EST