RE: [PATCH next v3 0/5] minmax: Relax type checks in min() and max().
From: David Laight
Date: Thu Aug 24 2023 - 05:06:15 EST
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
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)