[Libguestfs] [PATCH nbdkit 0/2] common: Add checked-overflow macros

Eric Blake
2021-11-09T19:45:00Z

On Tue, Nov 09, 2021 at 05:49:16PM +0000, Richard W.M. Jones
wrote:
> In common/vector/vector.c use GCC/Clang built-in overflow operators.
>
> The first patch is a neutral change which adds comments.  The second
> patch is the actual change.
>
> Add a new header "checked-overflow.h" which has the purpose of
> isolating the use of the built-ins to one file (in case we need to add
> a new compiler later).  Then use this in generic_vector_reserve.
>
> I tested this with GCC 11 and Clang 13.

That's the modern edge of the spectrum; will we be interfering with
compilation on older distros with older compilers?  I guess CI testing
can help find that out quickly.

>
> I verified by disassembly that "jo" (jump overflow) /
"jno" is used
> where it was not used previously, by both compilers.

Nice, and an argument in favor of doing this.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org