gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] [SCM] Gnash branch, master, updated. 8a15dbc96e1786dae6b0


From: Benjamin Wolsey
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. 8a15dbc96e1786dae6b0e527e80c07a5b1724f9b
Date: Thu, 25 Nov 2010 09:49:16 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  8a15dbc96e1786dae6b0e527e80c07a5b1724f9b (commit)
      from  003262b1a162226646a512afb927b6e7be5566f7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=8a15dbc96e1786dae6b0e527e80c07a5b1724f9b


commit 8a15dbc96e1786dae6b0e527e80c07a5b1724f9b
Author: Benjamin Wolsey <address@hidden>
Date:   Thu Nov 25 10:30:14 2010 +0100

    Restore undefined behaviour because Lenny doesn't have boost 1.35

diff --git a/libbase/GnashNumeric.h b/libbase/GnashNumeric.h
index 567811d..5518ae6 100644
--- a/libbase/GnashNumeric.h
+++ b/libbase/GnashNumeric.h
@@ -34,8 +34,6 @@
 #include <algorithm>
 #include <boost/cstdint.hpp>
 #include <limits>
-#include <boost/type_traits/make_signed.hpp>
-#include <boost/type_traits/make_unsigned.hpp>
 #include <boost/utility/enable_if.hpp>
 
 namespace gnash {
@@ -58,66 +56,6 @@ isFinite(double d)
 #endif
 }
 
-/// Convert an unsigned type to a signed type of the same width.
-//
-/// This mimics the conversion from a two's complement signed type
-/// to a corresponding unsigned type. This is the de facto default
-/// conversion on most i686 machines, but the behaviour is undefined
-/// *in all cases* in C++, and produces incorrect results on
-/// some platforms.
-//
-/// @tparam unsigned_type   The type to convert from
-/// @param t                The value to convert
-/// @return                 An unsigned type of the same width
-template<typename unsigned_type>
-typename boost::make_signed<unsigned_type>::type
-to_signed(unsigned_type t,
-    typename boost::enable_if<
-        typename boost::is_unsigned<unsigned_type> >::type* dummy = 0)
-{
-    (void)dummy;
-    typedef typename boost::make_signed<unsigned_type>::type signed_type;
-
-    // The max of the corresponding signed type can be represented in the
-    // unsigned type.
-    const unsigned_type max = std::numeric_limits<signed_type>::max();
-
-    if (t <= max) return t;
-
-    const signed_type x = t & max;
-
-    const signed_type min = std::numeric_limits<signed_type>::min();
-
-    return min + x;
-}
-
-/// Convert a signed type to an unsigned type of the same width.
-//
-/// This mimics the conversion from an unsigned type to a two's
-/// complement signed type. This is the de facto default
-/// conversion on most i686 machines, but the behaviour is undefined
-/// *in all cases* in C++, and produces incorrect results on
-/// some platforms.
-//
-/// @tparam signed_type     The type to convert from
-/// @param t                The value to convert
-/// @return                 A signed type of the same width
-template<typename signed_type>
-typename boost::make_unsigned<signed_type>::type
-to_unsigned(signed_type t,
-    typename boost::enable_if<
-        typename boost::is_signed<signed_type> >::type* dummy = 0)
-{
-    (void)dummy;
-
-    typedef typename boost::make_unsigned<signed_type>::type unsigned_type;
-
-    // Anything positive can be represented.
-    if (t >= 0) return t;
-
-    return std::numeric_limits<unsigned_type>::max() + t + 1;
-}
-
 inline double
 infinite_to_zero(double x)
 {
@@ -173,7 +111,7 @@ truncateWithFactor(double a)
                 std::numeric_limits<boost::int32_t>::min() / factor;
 
     if (a >= lowerSignedLimit && a <= upperSignedLimit) {
-        return to_signed<boost::uint32_t>(a * factor);
+        return static_cast<boost::int32_t>(a * factor);
     }
 
     // This slow truncation happens only in very unlikely cases.
diff --git a/libcore/SWFMatrix.cpp b/libcore/SWFMatrix.cpp
index 5d8cf94..682c00f 100644
--- a/libcore/SWFMatrix.cpp
+++ b/libcore/SWFMatrix.cpp
@@ -69,13 +69,9 @@ toFixed16(double a)
 inline boost::int32_t
 multiplyFixed16(boost::int32_t a, boost::int32_t b)
 {
-    // Overflows are permitted only in unsigned types, so
-    // convert using two's complement first.
-    const boost::uint32_t mult = 
-        (to_unsigned<boost::int64_t>(a) * to_unsigned<boost::int64_t>(b) + 
0x8000) >> 16;
+    return (static_cast<boost::int64_t>(a) *
+            static_cast<boost::int64_t>(b) + 0x8000) >> 16;
 
-    // Convert back.
-    return to_signed<boost::uint32_t>(mult);
 }
 
 } // anonymous namepace
diff --git a/libcore/vm/ASHandlers.cpp b/libcore/vm/ASHandlers.cpp
index a683b64..c68eb08 100644
--- a/libcore/vm/ASHandlers.cpp
+++ b/libcore/vm/ASHandlers.cpp
@@ -1517,10 +1517,8 @@ ActionChr(ActionExec& thread)
 {
     as_environment& env = thread.env;
     
-    // The conversion to unsigned happens before truncation;
-    // this is important.
-    const boost::uint16_t c = to_unsigned<boost::int32_t>(
-        toInt(env.top(0), getVM(env)));
+    // This is UB:
+    const boost::uint16_t c = toInt(env.top(0), getVM(env));
 
     // If the argument to chr() is '0', we return
     // nothing, not NULL
@@ -1665,10 +1663,8 @@ ActionMbChr(ActionExec& thread)
         // No need to return.
     }
 
-    // The conversion to unsigned happens before truncation;
-    // this is important.
-    const boost::uint16_t i = to_unsigned<boost::int32_t>(
-        toInt(env.top(0), getVM(env)));
+    // This is UB
+    const boost::uint16_t i = toInt(env.top(0), getVM(env));
     
     std::string out = utf8::encodeUnicodeCharacter(i);
     
@@ -3031,7 +3027,8 @@ ActionShiftRight(ActionExec& thread)
 {
     as_environment& env = thread.env;
 
-    boost::uint32_t amount = to_unsigned(toInt(env.top(0), getVM(env)));
+    // This is UB.
+    boost::uint32_t amount = toInt(env.top(0), getVM(env));
     boost::int32_t value = toInt(env.top(1), getVM(env));
 
     value = value >> amount;
@@ -3045,7 +3042,8 @@ ActionShiftRight2(ActionExec& thread)
 {
     as_environment& env = thread.env;
 
-    boost::uint32_t amount = to_unsigned(toInt(env.top(0), getVM(env))); 
+    // This is UB
+    boost::uint32_t amount = toInt(env.top(0), getVM(env)); 
     boost::int32_t value = toInt(env.top(1), getVM(env));
 
     value = boost::uint32_t(value) >> amount;

-----------------------------------------------------------------------

Summary of changes:
 libbase/GnashNumeric.h    |   64 +--------------------------------------------
 libcore/SWFMatrix.cpp     |    8 +----
 libcore/vm/ASHandlers.cpp |   18 +++++-------
 3 files changed, 11 insertions(+), 79 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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