gnash-commit
[Top][All Lists]
Advanced

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

Re: [Gnash-commit] gnash ChangeLog libbase/utility.h server/charac...


From: Benjamin Wolsey
Subject: Re: [Gnash-commit] gnash ChangeLog libbase/utility.h server/charac...
Date: Fri, 13 Jun 2008 17:28:14 +0200

>  inline boost::int32_t FloatToFixed16(float a)
>  {
> -    // There might be overflows, but we don't care in our specific case.
> -    return (boost::int32_t)(a * 65536.0f);
> +    // truncate when overflow occurs.
> +    return (boost::int32_t)(boost::uint32_t)(a * 65536.0f);
>  }
>  
>  inline boost::int32_t DoubleToFixed16(double a)
>  {
> -    // There might be overflows, but we don't care in our specific case.
> -    return (boost::int32_t)(a * 65536.0);
> +    // truncate when overflow occurs.
> +    return (boost::int32_t)(boost::uint32_t)(a * 65536.0);
>  }

>  inline double TWIPS_TO_PIXELS(int i) { return i / 20.0; }
> -inline int PIXELS_TO_TWIPS(double d) { return d * 20; }
> +// truncate when overflow occurs.
> +inline int PIXELS_TO_TWIPS(double d) { return (int)(unsigned int)(d * 20); }

All of these rely on undefined behaviour. Conversion from float to an
integer is undefined behaviour if the float value cannot be represented
in the integral value after truncation (i.e. when the fractional value
has been removed).

There has to be a way of doing it that doesn't make dangerous bugs
possible.

-bwy

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil


reply via email to

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