qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [PATCH 2/3] int128.h: Avoid undefined behaviours invo


From: Michael Tokarev
Subject: Re: [Qemu-trivial] [PATCH 2/3] int128.h: Avoid undefined behaviours involving signed arithmetic
Date: Sun, 06 Apr 2014 11:09:23 +0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10

28.03.2014 19:12, Peter Maydell wrote:
> Add casts when we're performing arithmetic on the .hi parts of an
> Int128, to avoid undefined behaviour.
[]
>  static inline Int128 int128_sub(Int128 a, Int128 b)
>  {
> -    return (Int128){ a.lo - b.lo, a.hi - b.hi - (a.lo < b.lo) };
> +    return (Int128){ a.lo - b.lo, (uint64_t)a.hi - b.hi - (a.lo < b.lo) };

What was wrong with this one?  I don't think casting to unsigned here is
a good idea.

Thanks,

/mjt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]