summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-bmp.c
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
commit95fe6f166755faecd50354f1ff3dfb4577fc86f2 (patch)
tree6d3c1a3f8278712ca24d9e28f63cccabb2a22e95 /gdk-pixbuf/io-bmp.c
parentf18329f2b7a6fa140c5c937ad554f07d7e6068f5 (diff)
downloadgdk-pixbuf-95fe6f166755faecd50354f1ff3dfb4577fc86f2.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)
Diffstat (limited to 'gdk-pixbuf/io-bmp.c')
-rw-r--r--gdk-pixbuf/io-bmp.c28
1 files changed, 16 insertions, 12 deletions
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;