[libgsf] Utils: fix C standard violation.



commit b1f8faba70cba56c4eddbce030ff4fce0d16cac5
Author: Morten Welinder <terra gnome org>
Date:   Sat Dec 7 22:03:02 2013 -0500

    Utils: fix C standard violation.

 ChangeLog       |    7 +++++++
 gsf/gsf-utils.h |   10 +++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6f4718a..fe3dd61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-12-07  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-utils.h (GSF_LE_GET_GUINT32): cast unsigned char to
+       guint32 before left-shifting by 24.  This avoids an implicit cast
+       to int followed by an overflowing left-shift which is undefined in
+       the C standard.
+
 2013-09-13  Morten Welinder  <terra gnome org>
 
        * gsf/gsf-infile-zip.c (zip_child_init): Fix translation marking,
diff --git a/gsf/gsf-utils.h b/gsf/gsf-utils.h
index 20edad1..01b53e1 100644
--- a/gsf/gsf-utils.h
+++ b/gsf/gsf-utils.h
@@ -58,11 +58,11 @@ G_BEGIN_DECLS
  *
  * Returns: interpreted data
  */
-#define GSF_LE_GET_GUINT32(p)                          \
-       (guint32)((((guint8 const *)(p))[0] << 0)  |    \
-                 (((guint8 const *)(p))[1] << 8)  |    \
-                 (((guint8 const *)(p))[2] << 16) |    \
-                 (((guint8 const *)(p))[3] << 24))
+#define GSF_LE_GET_GUINT32(p)                                  \
+       (guint32)(((guint32)((guint8 const *)(p))[0] << 0)  |   \
+                 ((guint32)((guint8 const *)(p))[1] << 8)  |   \
+                 ((guint32)((guint8 const *)(p))[2] << 16) |   \
+                 ((guint32)((guint8 const *)(p))[3] << 24))
 
 /**
  * GSF_LE_GET_GUINT64:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]