[Libguestfs] [PATCH nbdkit 2/2] common/include/checked-overflow.h: Provide fallback

Laszlo Ersek
Fri, 19 Nov 2021 09:57:30 -0000

On 11/18/21 16:27, Eric Blake wrote:
> On Thu, Nov 18, 2021 at 01:39:39PM +0100, Laszlo Ersek wrote:

>> (10) The (unsigned) type-generic macros could look something like this.
>> First, we'd need to check if the types of "a",
"b" and "result" were (i)
>> integers, (ii) unsigned, and (iii) had identical range.
>
> Check (i) is a nice safety valve.

Meanwhile I've realized that

  (typeof (a))-1 > 0

covers (i) and (ii) both, because all floating point types can represent
-1 (and exactly at that). So there is no need for

  (typeof (a))1 / 2 == 0

just for (i).

Thanks
Laszlo