Re: integer overflow checking in the kernel

Alan Somers <[email protected]>
Newsgroups gmane.os.freebsd.devel.hackers
Message-ID <CAOtMX2i_YMqYA=DP-pZMyUZ5V5N+TUt60xK6nN+_ZsjhK_wRtg@mail.gmail.com>
On Mon, Aug 10, 2026 at 4:13 PM Mark Johnston <[email protected]> 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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.