Re: integer overflow checking in the kernel

From: Alan Somers <asomers_at_freebsd.org>
Date: Mon, 10 Aug 2026 22:17:23 UTC
On Mon, Aug 10, 2026 at 4:13 PM Mark Johnston <markj@freebsd.org> wrote:
>
> In the kernel we don't have any dedicated macros or functions for
> checking for overflow in integer operations.  We have many open-coded
> checks, but it can be tricky to get those right in the face of integer
> promotion rules.
>
> I propose that we simply adopt the macros from C23's stdckdint.h.  These
> are just thin wrappers around __builtin_*_overflow.  I posted a patch
> which implements this at https://reviews.freebsd.org/D58773 and I also
> converted a couple of existing checks.
>
> Any reviews/thoughts/objections?

I think this is an excellent idea.  Let us not reinvent the wheel.