[gnumeric] Runtime: avoid undefined signed integer behaviour.



commit 98d8fc4ab5b8720ad56813abd0ef7e94fc6d351c
Author: Morten Welinder <terra gnome org>
Date:   Sat Dec 7 14:02:20 2013 -0500

    Runtime: avoid undefined signed integer behaviour.
    
    We did shifts with signed integers when we meant to use unsigned ones.

 ChangeLog       |    6 ++++++
 src/dependent.c |    8 ++++++--
 src/position.c  |    2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9d34356..a0f4f93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-07  welinder  <terra gnome org>
+
+       * src/position.c (gnm_cellref_hash): Avoid undefined signed integer
+       behaviour.
+       * src/dependent.c (deprange_hash): Ditto.
+
 2013-12-04  Morten Welinder  <terra gnome org>
 
        * src/sf-gamma.c (gamma_error_factor): Add extra term.
diff --git a/src/dependent.c b/src/dependent.c
index 718c960..174aaeb 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -837,8 +837,12 @@ typedef struct {
 static guint
 deprange_hash (DependencyRange const *r)
 {
-       return ((((r->range.start.row << 8) + r->range.end.row) << 8) +
-               (r->range.start.col << 8) + (r->range.end.col));
+       guint a = r->range.start.row;
+       guint b = r->range.end.row;
+       guint c = r->range.start.col;
+       guint d = r->range.end.col;
+
+       return (((((a << 8) + b) << 8) + c) << 8) + d;
 }
 
 static gint
diff --git a/src/position.c b/src/position.c
index ea85d76..b02096d 100644
--- a/src/position.c
+++ b/src/position.c
@@ -396,7 +396,7 @@ gnm_cellref_hash (GnmCellRef const *cr)
 {
        guint h = cr->row;
        h = (h << 16) | (h >> 16);
-       h ^= (cr->col << 2);
+       h ^= ((guint)cr->col << 2);
        if (cr->col_relative) h ^= 1;
        if (cr->row_relative) h ^= 2;
        return h;


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