[Swfdec] libswfdec/swfdec_bits.c

Benjamin Otte company at kemper.freedesktop.org
Wed Jul 11 07:40:57 PDT 2007


 libswfdec/swfdec_bits.c |   40 ++++++++++++++--------------------------
 1 files changed, 14 insertions(+), 26 deletions(-)

New commits:
diff-tree 0890f620c6b0a312176525a5f0977ed95b5314fe (from df8e44d9c530cc042e791cde0786cbea30afa373)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jul 11 16:41:01 2007 +0200

    don't access memory unaligned (fixes #11492)
    
    Hopefully fixes it...

diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index c8a5062..8ec6936 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -307,11 +307,9 @@ swfdec_bits_get_float (SwfdecBits * b)
 
   SWFDEC_BYTES_CHECK (b, 4);
 
-  conv.i = *((gint32 *) b->ptr);
+  conv.i = (b->ptr[3] << 24) | (b->ptr[2] << 16) | (b->ptr[1] << 8) | b->ptr[0];
   b->ptr += 4;
 
-  conv.i = GINT32_FROM_LE (conv.i);
-
   return conv.f;
 }
 
@@ -323,40 +321,30 @@ swfdec_bits_get_float (SwfdecBits * b)
  * use this command line:
  * python -c "import struct; print struct.unpack('8c', struct.pack('d', 7.949928895127363e-275))"
  */
-static double 
-swfdec_bits_double_to_host (double in)
+double
+swfdec_bits_get_double (SwfdecBits * b)
 {
   union {
     guint32 i[2];
     double d;
   } conv;
 
-  conv.d = in;
+  SWFDEC_BYTES_CHECK (b, 8);
+
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
-  {
-    int tmp = conv.i[0];
-    conv.i[0] = conv.i[1];
-    conv.i[1] = tmp;
-  }
+  conv.i[1] = (b->ptr[3] << 24) | (b->ptr[2] << 16) | (b->ptr[1] << 8) | b->ptr[0];
+  conv.i[0] = (b->ptr[7] << 24) | (b->ptr[6] << 16) | (b->ptr[5] << 8) | b->ptr[4];
 #else
-  conv.i[0] = GUINT32_FROM_LE (conv.i[0]);
-  conv.i[1] = GUINT32_FROM_LE (conv.i[1]);
+  conv.i[0] = (b->ptr[3] << 24) | (b->ptr[2] << 16) | (b->ptr[1] << 8) | b->ptr[0];
+  conv.i[1] = (b->ptr[7] << 24) | (b->ptr[6] << 16) | (b->ptr[5] << 8) | b->ptr[4];
+#if 0
+  conv.i[0] = (b->ptr[0] << 24) | (b->ptr[1] << 16) | (b->ptr[2] << 8) | b->ptr[3];
+  conv.i[1] = (b->ptr[4] << 24) | (b->ptr[5] << 16) | (b->ptr[6] << 8) | b->ptr[7];
+#endif
 #endif
-  return conv.d;
-}
-
-double
-swfdec_bits_get_double (SwfdecBits * b)
-{
-  double d;
-
-  SWFDEC_BYTES_CHECK (b, 8);
-
-  d = *((double *) b->ptr);
   b->ptr += 8;
-  d = swfdec_bits_double_to_host (d);
 
-  return d;
+  return conv.d;
 }
 
 double


More information about the Swfdec mailing list