integer overflow checking in the kernel
- Reply: Alan Somers : "Re: integer overflow checking in the kernel"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 10 Aug 2026 22:12:59 UTC
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?