diff options
author | Benjamin Otte <otte@gnome.org> | 2007-07-11 16:41:01 +0200 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2007-07-11 16:41:01 +0200 |
commit | 0890f620c6b0a312176525a5f0977ed95b5314fe (patch) | |
tree | ab2e7bb4c6a542796c5a4d82afe644d3f8b72435 | |
parent | df8e44d9c530cc042e791cde0786cbea30afa373 (diff) |
don't access memory unaligned (fixes #11492)0.4
Hopefully fixes it...
-rw-r--r-- | libswfdec/swfdec_bits.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c index c8a50622..8ec69365 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 |