summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2005-03-30 19:34:37 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2005-03-30 19:34:37 +0000
commit2aeadf5e681f24e2c4ca304a58b7a6bbee17f354 (patch)
treebc4c8a82dc24f6c64e96b9194f74631ce972f78d
parent15ea081b5fc55ccc3318ab09903fb1760a49ec11 (diff)
downloadgdk-pixbuf-2aeadf5e681f24e2c4ca304a58b7a6bbee17f354.tar.gz
Avoid bus errors due to unaligned access. (#168173, Morten Welinder, Ivan
2005-03-30 Matthias Clasen <mclasen@redhat.com> * io-bmp.c: Avoid bus errors due to unaligned access. (#168173, Morten Welinder, Ivan Wong)
-rw-r--r--gdk-pixbuf/ChangeLog5
-rw-r--r--gdk-pixbuf/io-bmp.c28
2 files changed, 21 insertions, 12 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog
index 64b349384..c894d6ad1 100644
--- a/gdk-pixbuf/ChangeLog
+++ b/gdk-pixbuf/ChangeLog
@@ -1,3 +1,8 @@
+2005-03-30 Matthias Clasen <mclasen@redhat.com>
+
+ * io-bmp.c: Avoid bus errors due to unaligned access. (#168173,
+ Morten Welinder, Ivan Wong)
+
2005-03-29 Matthias Clasen <mclasen@redhat.com>
* io-tga.c (parse_rle_data): Fix the update areas for incremental
diff --git a/gdk-pixbuf/io-bmp.c b/gdk-pixbuf/io-bmp.c
index f33f9f5e5..4cdcc112c 100644
--- a/gdk-pixbuf/io-bmp.c
+++ b/gdk-pixbuf/io-bmp.c
@@ -1137,10 +1137,14 @@ gdk_pixbuf__bmp_image_load_increment(gpointer data,
}
/* for our convenience when filling file header */
-#define put16u(buf,data) { *(guint16*)(buf) = GUINT16_TO_LE (data); buf += 2; }
-#define put32u(buf,data) { *(guint32*)(buf) = GUINT32_TO_LE (data); buf += 4; }
-#define put16(buf,data) { *(gint16*)(buf) = GINT16_TO_LE (data); buf += 2; }
-#define put32(buf,data) { *(gint32*)(buf) = GINT32_TO_LE (data); buf += 4; }
+#define put16(buf,data) { guint16 x; \
+ x = GUINT16_TO_LE (data); \
+ memcpy(buf, &x, 2); \
+ buf += 2; }
+#define put32(buf,data) { guint32 x; \
+ x = GUINT32_TO_LE (data); \
+ memcpy(buf, &x, 4); \
+ buf += 4; }
static gboolean
gdk_pixbuf__bmp_image_save_to_callback (GdkPixbufSaveFunc save_func,
@@ -1166,22 +1170,22 @@ gdk_pixbuf__bmp_image_save_to_callback (GdkPixbufSaveFunc save_func,
dst = BFH_BIH;
*dst++ = 'B'; /* bfType */
*dst++ = 'M';
- put32u (dst, size + 14 + 40); /* bfSize */
- put32u (dst, 0); /* bfReserved1 + bfReserved2 */
- put32u (dst, 14 + 40); /* bfOffBits */
+ put32 (dst, size + 14 + 40); /* bfSize */
+ put32 (dst, 0); /* bfReserved1 + bfReserved2 */
+ put32 (dst, 14 + 40); /* bfOffBits */
/* filling BIH */
- put32u (dst, 40); /* biSize */
+ put32 (dst, 40); /* biSize */
put32 (dst, width); /* biWidth */
put32 (dst, height); /* biHeight */
put16 (dst, 1); /* biPlanes */
put16 (dst, 24); /* biBitCount */
- put32u (dst, BI_RGB); /* biCompression */
- put32u (dst, size); /* biSizeImage */
+ put32 (dst, BI_RGB); /* biCompression */
+ put32 (dst, size); /* biSizeImage */
put32 (dst, 0); /* biXPelsPerMeter */
put32 (dst, 0); /* biYPelsPerMeter */
- put32u (dst, 0); /* biClrUsed */
- put32u (dst, 0); /* biClrImportant */
+ put32 (dst, 0); /* biClrUsed */
+ put32 (dst, 0); /* biClrImportant */
if (!save_func (BFH_BIH, 14 + 40, error, user_data))
return FALSE;