Re: buffer_head.b_bsize type

From: William Lee Irwin III (wli@holomorphy.com)
Date: Fri May 30 2003 - 21:29:28 EST


On Fri, May 30, 2003 at 04:24:34PM +0200, Andries Brouwer wrote:
> Not about this particular case, but as a general remark:
> Use of unsigned is dangerous - use of int is far preferable,
> everywhere that is possible.
> With ints the test a+b > c is equivalent to the test a > c-b.
> Intuition works.
> As soon as there is some unsigned in an expression comparisons
> get counterintuitive because -1 is very large.
> Thus, 1+sizeof(int) > 3 is true, but 1 > 3-sizeof(int) is false.
> It has happened several times that kernel code was broken because
> some variable (that always was nonnegative) was made unsigned.

I don't see what the big deal is. Arithmetic in Z/2**32Z or whatever
doesn't really define a comparison, we just artificially impose our
favorite residues and have to check various preconditions for the
results of comparisons to make sense (which obviously aren't checked
in your example of garbage produced by a comparison).

You are right in that some attempt at an audit should be done if it
were to be changed, of course. I generally think of it as easy, and
assume it will be done.

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