Re: [PATCH 1/1] minmax.h: Slightly relax the type checking done by min() and max().
From: Linus Torvalds
Date: Sun Nov 27 2022 - 15:36:55 EST
On Fri, Nov 25, 2022 at 7:00 AM David Laight <David.Laight@xxxxxxxxxx> wrote:
>
> - Skip the type test if either argument is a positive 'int' constant.
> Instead cast the constant to 'int', the compiler may promote it
> back to 'unsigned int' when doing the test.
No. This looks very wrong to me.
Maybe I'm mis-reading something, but it looks like this makes a
"sizeof()" essentially be compatible with an "int" variable.
That is horrendously wrong. It should warn.
If you are doing a "min(i,sizeof(X))", and "i" is a signed integer,
then something is wrong. What does that code expect? It shouldn't
silently say "this is ok", because it most definitely isn't.
So maybe I'm mis-reading this all and it doesn't actually do what I
think it does, but this seems to relax things *much* too much.
There's a reason we require types to be compatible, and you just
removed some of the important signedness checks.
Linus