[libgsf] Utils: Ensure GSF_LE_SET_GU?INT{16, 32, 64} do not depend on C implementation
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] Utils: Ensure GSF_LE_SET_GU?INT{16, 32, 64} do not depend on C implementation
- Date: Mon, 1 Dec 2014 22:27:39 +0000 (UTC)
commit bfec34e0ea1ecc76aa44d593ab2b0e2677f1e63f
Author: Morten Welinder <terra gnome org>
Date: Mon Dec 1 17:25:57 2014 -0500
Utils: Ensure GSF_LE_SET_GU?INT{16,32,64} do not depend on C implementation
Shifting negative values to the right is implementation defined.
ChangeLog | 4 ++++
NEWS | 1 +
gsf/gsf-outfile-zip.c | 2 +-
gsf/gsf-utils.h | 32 ++++++++++++++++----------------
4 files changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 34a06ad..8429c20 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@
2014-11-30 Morten Welinder <terra gnome org>
+ * gsf/gsf-utils.h (GSF_LE_SET_GU?INT{16,32,64}): Add casts to make
+ things more function-like and avoid implementation defined
+ behaviour.
+
* gsf/gsf-outfile-zip.c (zip_dirent_write): The the archive is in
auto mode and the member is not using a zip64 extra field, use an
IGNORE extra field to work around known zipinfo bug.
diff --git a/NEWS b/NEWS
index c145ef0..389a601 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Morten:
* Write zip archives with more than 64k+ members.
* Store unix modtime in zip. (Until that overflows.)
* Fix seekability checks in GsfOutputIOChannel.
+ * Avoid implementation defined behaviour of shifts.
--------------------------------------------------------------------------
libgsf 1.14.30
diff --git a/gsf/gsf-outfile-zip.c b/gsf/gsf-outfile-zip.c
index ecfe7d8..4e921a0 100644
--- a/gsf/gsf-outfile-zip.c
+++ b/gsf/gsf-outfile-zip.c
@@ -170,7 +170,7 @@ zip_dirent_write (GsfOutfileZip *zip, const GsfZipDirent *dirent)
char tmp[8];
/*
- * We could unconditinally store the offset here, but
+ * We could unconditionally store the offset here, but
* zipinfo has a known bug in which it fails to account
* for differences in extra fields between the global
* and the local headers. So we try to make them the
diff --git a/gsf/gsf-utils.h b/gsf/gsf-utils.h
index 01b53e1..359c445 100644
--- a/gsf/gsf-utils.h
+++ b/gsf/gsf-utils.h
@@ -155,9 +155,9 @@ double gsf_le_get_double (void const *p);
*
* Store @dat in little endian order in memory pointed to by @p.
*/
-#define GSF_LE_SET_GUINT16(p, dat) \
- ((*((guint8 *)(p) + 0) = ((dat) & 0xff)),\
- (*((guint8 *)(p) + 1) = ((dat) >> 8) & 0xff))
+#define GSF_LE_SET_GUINT16(p, dat) \
+ ((*((guint8 *)(p) + 0) = (guint8)((guint16)(dat)) & 0xff), \
+ (*((guint8 *)(p) + 1) = (guint8)((guint16)(dat) >> 8) & 0xff))
/**
* GSF_LE_SET_GUINT32:
@@ -166,11 +166,11 @@ double gsf_le_get_double (void const *p);
*
* Store @dat in little endian order in memory pointed to by @p.
*/
-#define GSF_LE_SET_GUINT32(p, dat) \
- ((*((guint8 *)(p) + 0) = (guchar) ((dat)) & 0xff), \
- (*((guint8 *)(p) + 1) = (guchar) ((dat) >> 8) & 0xff), \
- (*((guint8 *)(p) + 2) = (guchar) ((dat) >> 16) & 0xff), \
- (*((guint8 *)(p) + 3) = (guchar) ((dat) >> 24) & 0xff))
+#define GSF_LE_SET_GUINT32(p, dat) \
+ ((*((guint8 *)(p) + 0) = (guint8)((guint32)(dat)) & 0xff), \
+ (*((guint8 *)(p) + 1) = (guint8)((guint32)(dat) >> 8) & 0xff), \
+ (*((guint8 *)(p) + 2) = (guint8)((guint32)(dat) >> 16) & 0xff), \
+ (*((guint8 *)(p) + 3) = (guint8)((guint32)(dat) >> 24) & 0xff))
/**
* GSF_LE_SET_GUINT64:
@@ -180,14 +180,14 @@ double gsf_le_get_double (void const *p);
* Store @dat in little endian order in memory pointed to by @p.
*/
#define GSF_LE_SET_GUINT64(p, dat) \
- ((*((guint8 *)(p) + 0) = (guchar) ((dat)) & 0xff), \
- (*((guint8 *)(p) + 1) = (guchar) ((dat) >> 8) & 0xff), \
- (*((guint8 *)(p) + 2) = (guchar) ((dat) >> 16) & 0xff), \
- (*((guint8 *)(p) + 3) = (guchar) ((dat) >> 24) & 0xff), \
- (*((guint8 *)(p) + 4) = (guchar) ((dat) >> 32) & 0xff), \
- (*((guint8 *)(p) + 5) = (guchar) ((dat) >> 40) & 0xff), \
- (*((guint8 *)(p) + 6) = (guchar) ((dat) >> 48) & 0xff), \
- (*((guint8 *)(p) + 7) = (guchar) ((dat) >> 56) & 0xff))
+ ((*((guint8 *)(p) + 0) = (guint8)((guint64)(dat)) & 0xff), \
+ (*((guint8 *)(p) + 1) = (guint8)((guint64)(dat) >> 8) & 0xff), \
+ (*((guint8 *)(p) + 2) = (guint8)((guint64)(dat) >> 16) & 0xff), \
+ (*((guint8 *)(p) + 3) = (guint8)((guint64)(dat) >> 24) & 0xff), \
+ (*((guint8 *)(p) + 4) = (guint8)((guint64)(dat) >> 32) & 0xff), \
+ (*((guint8 *)(p) + 5) = (guint8)((guint64)(dat) >> 40) & 0xff), \
+ (*((guint8 *)(p) + 6) = (guint8)((guint64)(dat) >> 48) & 0xff), \
+ (*((guint8 *)(p) + 7) = (guint8)((guint64)(dat) >> 56) & 0xff))
/**
* GSF_LE_SET_GINT8:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]