Laszlo Ersek
2021-Nov-19 09:57 UTC
[Libguestfs] [PATCH nbdkit 2/2] common/include/checked-overflow.h: Provide fallback
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
Richard W.M. Jones
2021-Nov-22 22:31 UTC
[Libguestfs] [PATCH nbdkit 2/2] common/include/checked-overflow.h: Provide fallback
(Catching up ...) The maths looked reasonable. Did you have a version of the patch for review? My only other thought is that a simple set of tests could be good. However it's not worth having tests that only test if __builtin* functions are correct (hopefully GCC is already testing that). So tests would have to check the fallback macros are correct, even if they are not used on the current platform. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org