[PATCH xserver] squash! sync: Convert from "CARD64" to int64_t.

Michel Dänzer michel at daenzer.net
Fri Aug 25 00:57:20 UTC 2017


On 25/08/17 03:57 AM, Eric Anholt wrote:
> ---
> 
> We pass the overflow unit tests both before and after this change, but
> this should be safer.
> 
>  include/misc.h | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/include/misc.h b/include/misc.h
> index 0feeaebc7c1a..9d0e422e36b4 100644
> --- a/include/misc.h
> +++ b/include/misc.h
> @@ -327,7 +327,11 @@ bswap_32(uint32_t x)
>  static inline Bool
>  checked_int64_add(int64_t *out, int64_t a, int64_t b)
>  {
> -    int64_t result = a + b;
> +    /* Do the potentially overflowing math as uint64_t, as signed
> +     * integers in C are undefined on overflow (and the compiler may
> +     * optimize out our overflow check below, otherwise)
> +     */
> +    int64_t result = (uint64_t)a + (uint64_t)b;

Is assigning an unsigned value with the MSB set to a signed variable
well-defined in C?


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the xorg-devel mailing list