[evolution] Address some issues reported by Undefined Behavior Sanitizer



commit d958c1cb7a51a1f448bd8edb28a12deac01b0e10
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 25 11:36:32 2018 +0100

    Address some issues reported by Undefined Behavior Sanitizer
    
    The runtime warnings were:
    - null pointer passed as argument NNN, which is declared to never be null
    - left shift of MMM by NNN places cannot be represented in type 'int'

 src/e-util/e-bit-array.c           |    2 +-
 src/e-util/e-canvas-background.c   |   11 +++--------
 src/e-util/e-table-sort-info.c     |   28 ++++++++++++++++++----------
 src/e-util/e-text.c                |   10 ++--------
 src/mail/e-mail-label-list-store.c |    4 +---
 5 files changed, 25 insertions(+), 30 deletions(-)
---
diff --git a/src/e-util/e-bit-array.c b/src/e-util/e-bit-array.c
index 0f87e43..33c6828 100644
--- a/src/e-util/e-bit-array.c
+++ b/src/e-util/e-bit-array.c
@@ -224,7 +224,7 @@ e_bit_array_foreach (EBitArray *bit_array,
        }
 }
 
-#define PART(x,n) (((x) & (0x01010101 << n)) >> n)
+#define PART(x,n) ((guint32) ((((guint64) x) & (((guint64) 0x01010101) << n)) >> n))
 #define SECTION(x, n) (((x) >> (n * 8)) & 0xff)
 
 /**
diff --git a/src/e-util/e-canvas-background.c b/src/e-util/e-canvas-background.c
index 36af28a..8da675b 100644
--- a/src/e-util/e-canvas-background.c
+++ b/src/e-util/e-canvas-background.c
@@ -36,6 +36,7 @@
 
 #include "e-canvas.h"
 #include "e-canvas-utils.h"
+#include "e-misc-utils.h"
 
 #define E_CANVAS_BACKGROUND_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
@@ -120,10 +121,7 @@ ecb_set_property (GObject *object,
        case PROP_FILL_COLOR:
                if (g_value_get_string (value) &&
                    gdk_color_parse (g_value_get_string (value), &color)) {
-                       ecb->priv->rgba = ((color.red & 0xff00) << 16 |
-                                          (color.green & 0xff00) << 8 |
-                                          (color.blue & 0xff00) |
-                                          0xff);
+                       ecb->priv->rgba = ((e_color_to_value (&color) & 0xffffff) << 8) | 0xff;
                }
                break;
 
@@ -133,10 +131,7 @@ ecb_set_property (GObject *object,
                        color = *pcolor;
                }
 
-               ecb->priv->rgba = ((color.red & 0xff00) << 16 |
-                                  (color.green & 0xff00) << 8 |
-                                  (color.blue & 0xff00) |
-                                  0xff);
+               ecb->priv->rgba = ((e_color_to_value (&color) & 0xffffff) << 8) | 0xff;
                break;
 
        case PROP_FILL_COLOR_RGBA:
diff --git a/src/e-util/e-table-sort-info.c b/src/e-util/e-table-sort-info.c
index e36a7f5..5d84284 100644
--- a/src/e-util/e-table-sort-info.c
+++ b/src/e-util/e-table-sort-info.c
@@ -933,11 +933,15 @@ e_table_sort_info_duplicate (ETableSortInfo *sort_info)
        g_array_set_size (
                new_info->priv->groupings,
                sort_info->priv->groupings->len);
-       memmove (
-               new_info->priv->groupings->data,
-               sort_info->priv->groupings->data,
-               sort_info->priv->groupings->len *
-               g_array_get_element_size (sort_info->priv->groupings));
+       if (new_info->priv->groupings->data &&
+           sort_info->priv->groupings->data &&
+           sort_info->priv->groupings->len) {
+               memmove (
+                       new_info->priv->groupings->data,
+                       sort_info->priv->groupings->data,
+                       sort_info->priv->groupings->len *
+                       g_array_get_element_size (sort_info->priv->groupings));
+       }
 
        for (ii = 0; ii < new_info->priv->groupings->len; ii++) {
                ColumnData *column_data;
@@ -950,11 +954,15 @@ e_table_sort_info_duplicate (ETableSortInfo *sort_info)
        g_array_set_size (
                new_info->priv->sortings,
                sort_info->priv->sortings->len);
-       memmove (
-               new_info->priv->sortings->data,
-               sort_info->priv->sortings->data,
-               sort_info->priv->sortings->len *
-               g_array_get_element_size (sort_info->priv->sortings));
+       if (new_info->priv->sortings->data &&
+           sort_info->priv->sortings->data &&
+           sort_info->priv->sortings->len) {
+               memmove (
+                       new_info->priv->sortings->data,
+                       sort_info->priv->sortings->data,
+                       sort_info->priv->sortings->len *
+                       g_array_get_element_size (sort_info->priv->sortings));
+       }
 
        for (ii = 0; ii < new_info->priv->sortings->len; ii++) {
                ColumnData *column_data;
diff --git a/src/e-util/e-text.c b/src/e-util/e-text.c
index b6159d2..1655775 100644
--- a/src/e-util/e-text.c
+++ b/src/e-util/e-text.c
@@ -752,10 +752,7 @@ e_text_set_property (GObject *object,
                        break;
                }
 
-               text->rgba = ((color.red & 0xff00) << 16 |
-                             (color.green & 0xff00) << 8 |
-                             (color.blue & 0xff00) |
-                             0xff);
+               text->rgba = ((e_color_to_value (&color) & 0xffffff) << 8) | 0xff;
                text->rgba_set = TRUE;
                text->needs_redraw = 1;
                needs_update = 1;
@@ -767,10 +764,7 @@ e_text_set_property (GObject *object,
                        color = *pcolor;
                }
 
-               text->rgba = ((color.red & 0xff00) << 16 |
-                             (color.green & 0xff00) << 8 |
-                             (color.blue & 0xff00) |
-                             0xff);
+               text->rgba = ((e_color_to_value (&color) & 0xffffff) << 8) | 0xff;
                text->rgba_set = TRUE;
                text->needs_redraw = 1;
                needs_update = 1;
diff --git a/src/mail/e-mail-label-list-store.c b/src/mail/e-mail-label-list-store.c
index 4a624a2..7494a43 100644
--- a/src/mail/e-mail-label-list-store.c
+++ b/src/mail/e-mail-label-list-store.c
@@ -184,9 +184,7 @@ mail_label_list_store_get_stock_id (EMailLabelListStore *store,
                GdkPixbuf *pixbuf;
                guint32 pixel;
 
-               pixel = ((color.red & 0xFF00) << 16) +
-                       ((color.green & 0xFF00) << 8) +
-                       (color.blue & 0xFF00);
+               pixel = (e_color_to_value (&color) & 0xffffff) << 8;
 
                pixbuf = gdk_pixbuf_new (
                        GDK_COLORSPACE_RGB, FALSE, 8, 16, 16);


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