Re: [PATCH 1/1] minmax.h: Slightly relax the type checking done by min() and max().
From: Linus Torvalds
Date: Sun Nov 27 2022 - 16:54:46 EST
On Sun, Nov 27, 2022 at 1:42 PM David Laight <David.Laight@xxxxxxxxxx> wrote:
>
> Why should it be a problem?
> min(-4, sizeof(X)) becomes min(-4, (int)sizeof(X)) and thus -4.
> Without the cast the -4 is converted to a very large unsigned
> value so the result is sizeof(X) - not at all expected.
That is EXACTLY the problem.
You even enumerate it, and work through exactly what happens, and then
you STILL say "this is not a problem".
It damn well is a HUGE problem. When people say "I need my offset to
be smaller than the size of the object", then a value like -4 IS NOT
ACCEPTABLE. It should cause a huge type warning about how the test was
broken.
David, this is literally *EXACTLY* why we have those strict type issues.
The fact that you don't even seem to realize why this would be a
problem makes me NAK this patch so hard that it isn't even funny.
Andrew, please remove this from your queue. It's not even remotely
acceptable. I was hoping I was misreading the patch, but it turns out
that this "relax the rules way too much" was apparently intentional.
Linus