RE: [PATCH next v3 0/5] minmax: Relax type checks in min() and max().

David Laight
2023-08-24T09:06:15Z

From: Linus Torvalds
> Sent: Wednesday, August 23, 2023 4:32 PM
...
> That might get rid of a number of the more annoying cases.

The one it leaves is code like:

int length = get_length(...);
if (length <= 0)
return error:
do {
frag_len = some_min_function(length, PAGE_SIZE);
...
} while ((length -= frag_len) != 0);

As written it is ok for all reasonable some_min_function().

But if the (length <= 0) test is missing it really doesn't
matter what some_min_function() returns because the code
isn't going to do anything sensible - and may just loop.

About the only thing you could do is add a run-time check
and then BUG() if negative.
But that is horrid...

David