Re: [PATCH v1 0/3] Add ENDOF(), and use it to fix off-by-one bugs

From: Kees Cook
Date: Thu Sep 25 2025 - 20:00:38 EST


On Thu, Sep 25, 2025 at 01:48:14PM -0700, Andrew Morton wrote:
> Patchset seems reasonable, I guess. But I'm not loving "ENDOF". End
> of what - is that like __etext? "ARRAY_END" matches "ARRAY_SIZE" quite
> nicely, no? And it much better describes what the thing does.

And it's really ARRAY_BEYOND. ;) I don't really like having APIs that
require holding pointers that are actively invalid, either.

u8 array[10];
u8 *first = array; // valid address
u8 *last = &array[ARRAY_SIZE(array) - 1]; // valid address

for (u8 *c = first; c <= last; c++)
putc(*c);
// c would now be invalid but has left scope so it cannot be used

--
Kees Cook