]> Pileus Git - ~andy/gtk/commitdiff
Fix alignment problem in deserialization, (#65785, reported by Hidetoshi
authorOwen Taylor <otaylor@redhat.com>
Fri, 30 Nov 2001 21:01:01 +0000 (21:01 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Fri, 30 Nov 2001 21:01:01 +0000 (21:01 +0000)
Fri Nov 30 15:55:34 2001  Owen Taylor  <otaylor@redhat.com>
* gdk-pixdata.c (gdk_pixdata_deserialize): Fix
alignment problem in deserialization, (#65785,
reported by Hidetoshi Tajima)

gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixdata.c

index abfe6f89cc097f9d081ed32930b28e5f36c3b5b5..be6132a6a98b79bdf1788098b41a71822cc94503 100644 (file)
@@ -1,3 +1,9 @@
+Fri Nov 30 15:55:34 2001  Owen Taylor  <otaylor@redhat.com>
+
+       * gdk-pixdata.c (gdk_pixdata_deserialize): Fix
+       alignment problem in deserialization, (#65785,
+       reported by Hidetoshi Tajima)
+
 2001-11-28  Manish Singh  <yosh@gimp.org>
 
        * gdk-pixbuf/io-bmp.c (gdk_pixbuf__bmp_image_load_increment): Fill
index 57e2abecf6a37d06f51b05f610ca6e7f4148c7e3..3c61497e935d4fc43098c5526d851224205e2fe6 100644 (file)
@@ -157,6 +157,13 @@ gdk_pixdata_serialize (const GdkPixdata *pixdata,
   return FALSE; \
 }
 
+static inline const guint8 *
+get_uint32 (const guint8 *stream, guint *result)
+{
+  *result = (stream[0] << 24) + (stream[1] << 16) + (stream[2] << 8) + stream[3];
+  return stream + 4;
+}
+
 /**
  * gdk_pixdata_deserialize:
  * @pixdata: a #GdkPixdata structure to be filled in.
@@ -181,7 +188,6 @@ gdk_pixdata_deserialize (GdkPixdata   *pixdata,
                         const guint8 *stream,
                         GError      **error)
 {
-  guint32 *istream;
   guint color_type, sample_width, encoding;
 
   g_return_val_if_fail (pixdata != NULL, FALSE);
@@ -191,21 +197,14 @@ gdk_pixdata_deserialize (GdkPixdata   *pixdata,
 
 
   /* deserialize header */
-  istream = (guint32*) stream;
-  /*
-   * the deserialization of GdkPixdata will fail (at least on win32 with msvc 5.0) 
-   * with 'g_ntohl(*istream++)' because the guint32 istream pointer is only 
-   * incremented by 1 byte, if it is done within the g_ntohl() macro.
-   * Probably working around just another compiler bug ... --HB
-   */
-  pixdata->magic = g_ntohl (*istream); istream++;
-  pixdata->length = g_ntohl (*istream); istream++;
+  stream = get_uint32 (stream, &pixdata->magic);
+  stream = get_uint32 (stream, &pixdata->length);
   if (pixdata->magic != GDK_PIXBUF_MAGIC_NUMBER || pixdata->length < GDK_PIXDATA_HEADER_LENGTH)
     return_header_corrupt (error);
-  pixdata->pixdata_type = g_ntohl (*istream); istream++;
-  pixdata->rowstride = g_ntohl (*istream); istream++;
-  pixdata->width = g_ntohl (*istream); istream++;
-  pixdata->height = g_ntohl (*istream);  istream++;
+  stream = get_uint32 (stream, &pixdata->pixdata_type);
+  stream = get_uint32 (stream, &pixdata->rowstride);
+  stream = get_uint32 (stream, &pixdata->width);
+  stream = get_uint32 (stream, &pixdata->height);
   if (pixdata->width < 1 || pixdata->height < 1 ||
       pixdata->rowstride < pixdata->width)
     return_header_corrupt (error);
@@ -222,7 +221,7 @@ gdk_pixdata_deserialize (GdkPixdata   *pixdata,
   /* deserialize pixel data */
   if (stream_length < pixdata->length - GDK_PIXDATA_HEADER_LENGTH)
     return_pixel_corrupt (error);
-  pixdata->pixel_data = (guint8*) istream;
+  pixdata->pixel_data = (guint8 *)stream;
 
   return TRUE;
 }