]> Pileus Git - ~andy/gtk/commitdiff
Avoid unaligned accesses that cause problems on some architectures. (patch
authorMatthias Clasen <mclasen@redhat.com>
Sun, 11 Nov 2007 03:24:06 +0000 (03:24 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 11 Nov 2007 03:24:06 +0000 (03:24 +0000)
2007-11-10  Matthias Clasen <mclasen@redhat.com>

        * io-jpeg.c: Avoid unaligned accesses that cause
        problems on some architectures.  (patch by David Miller)

svn path=/trunk/; revision=18982

gdk-pixbuf/ChangeLog
gdk-pixbuf/io-jpeg.c

index 7c86025f42c79dd68327fc8cab2b7898cbd61014..c3cfcfddcf9152cbe085c07d3bb0aa554385b23e 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-10  Matthias Clasen <mclasen@redhat.com>
+
+       * io-jpeg.c: Avoid unaligned accesses that cause
+       problems on some architectures.  (patch by David Miller)
+
 2007-10-16  Matthias Clasen <mclasen@redhat.com>
 
        * === Released 2.12.1 ===
index 67327162bdcac4f247cb410922fef224cb4b0d40..fdcc3e2cb45bdfba99fd6511d27f8d5eb5fc6634 100644 (file)
@@ -292,6 +292,26 @@ const char types[] = {0x00, 0x01, 0x01, 0x02, 0x04, 0x08, 0x00,
 #define EXIF_JPEG_MARKER   JPEG_APP0+1
 #define EXIF_IDENT_STRING  "Exif\000\000"
 
+static unsigned short de_get16(void *ptr, guint endian)
+{
+       unsigned short val;
+
+       memcpy(&val, ptr, sizeof(val));
+       val = DE_ENDIAN16(val);
+
+       return val;
+}
+
+static unsigned int de_get32(void *ptr, guint endian)
+{
+       unsigned int val;
+
+       memcpy(&val, ptr, sizeof(val));
+       val = DE_ENDIAN32(val);
+
+       return val;
+}
+
 static gint 
 get_orientation (j_decompress_ptr cinfo)
 {
@@ -382,7 +402,7 @@ get_orientation (j_decompress_ptr cinfo)
         orient_tag_id = ENDIAN16_IT(0x112);
  
         /* Read out the offset pointer to IFD0 */
-        offset  = DE_ENDIAN32(*((unsigned long*) (&exif_marker->data[i] + 4)));
+        offset  = de_get32(&exif_marker->data[i] + 4, endian);
        i       = i + offset;
 
        /* Check that we still are within the buffer and can read the tag count */
@@ -391,7 +411,7 @@ get_orientation (j_decompress_ptr cinfo)
 
        /* Find out how many tags we have in IFD0. As per the TIFF spec, the first
           two bytes of the IFD contain a count of the number of tags. */
-       tags    = DE_ENDIAN16(*((unsigned short*) (&exif_marker->data[i])));
+       tags    = de_get16(&exif_marker->data[i], endian);
        i       = i + 2;
 
        /* Check that we still have enough data for all tags to check. The tags
@@ -402,8 +422,8 @@ get_orientation (j_decompress_ptr cinfo)
 
        /* Check through IFD0 for tags of interest */
        while (tags--){
-               type   = DE_ENDIAN16(*((unsigned short*)(&exif_marker->data[i + 2])));
-               count  = DE_ENDIAN32(*((unsigned long*) (&exif_marker->data[i + 4])));
+               type   = de_get16(&exif_marker->data[i + 2], endian);
+               count  = de_get32(&exif_marker->data[i + 4], endian);
 
                /* Is this the orientation tag? */
                if (memcmp (&exif_marker->data[i], (char *) &orient_tag_id, 2) == 0){ 
@@ -414,7 +434,7 @@ get_orientation (j_decompress_ptr cinfo)
 
                        /* Return the orientation value. Within the 12-byte block, the
                           pointer to the actual data is at offset 8. */
-                       ret = DE_ENDIAN16(*((unsigned short*) (&exif_marker->data[i + 8])));
+                       ret =  de_get16(&exif_marker->data[i + 8], endian);
                        return ret <= 8 ? ret : 0;
                }
                /* move the pointer to the next 12-byte tag field. */