[gnumeric] Cleanup: avoid double NULL check.



commit b097aebe68a88cb5a70ec3901da611ff055c6d79
Author: Morten Welinder <terra gnome org>
Date:   Wed May 9 19:36:19 2018 -0400

    Cleanup: avoid double NULL check.
    
    go_string_unref, style_color_unref, and gnm_style_border_unref are all
    perfectly happy with NULL args so don't check before calling.

 plugins/excel/excel-xml-read.c   |    3 +-
 plugins/excel/ms-excel-read.c    |   12 +++------
 plugins/excel/xlsx-read.c        |    5 +--
 src/dialogs/dialog-cell-format.c |    3 +-
 src/expr-name.c                  |    6 +---
 src/func.c                       |    3 +-
 src/input-msg.c                  |   13 ++++------
 src/mstyle.c                     |    3 +-
 src/style-border.c               |   12 +++------
 src/style-color.c                |   46 ++++++++++++++------------------------
 src/validation.c                 |   14 +++++------
 tools/check-gfrees               |    8 +++---
 12 files changed, 48 insertions(+), 80 deletions(-)
---
diff --git a/plugins/excel/excel-xml-read.c b/plugins/excel/excel-xml-read.c
index 6c8ba84..dc5ddf3 100644
--- a/plugins/excel/excel-xml-read.c
+++ b/plugins/excel/excel-xml-read.c
@@ -638,8 +638,7 @@ xl_xml_border (GsfXMLIn *xin, xmlChar const **attrs)
                else if (attr_int (xin, attrs, XL_NS_SS, "Weight", &weight))
                        ;
                else if ((new_color = attr_color (xin, attrs, XL_NS_SS, "Color"))) {
-                       if (color)
-                               style_color_unref (color);
+                       style_color_unref (color);
                        color = new_color;
                } else
                        unknown_attr (xin, attrs, "Style::Border");
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 6d05b38..3e9da45 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -1907,8 +1907,7 @@ excel_palette_destroy (ExcelPalette *pal)
        g_free (pal->green);
        g_free (pal->blue);
        for (lp = 0; lp < pal->length; lp++)
-               if (pal->gnm_colors[lp])
-                       style_color_unref (pal->gnm_colors[lp]);
+               style_color_unref (pal->gnm_colors[lp]);
        g_free (pal->gnm_colors);
        g_free (pal);
 }
@@ -2306,10 +2305,8 @@ excel_set_xf (ExcelReadSheet *esheet, BiffQuery *q)
                        /* adjacent borders  */
                        range_init (&range, col, row, col, row);
                        sheet_style_apply_border (sheet, &range, overlay);
-                       if (overlay[GNM_STYLE_BORDER_TOP])
-                               gnm_style_border_unref (overlay[GNM_STYLE_BORDER_TOP]);
-                       if (overlay[GNM_STYLE_BORDER_LEFT])
-                               gnm_style_border_unref (overlay[GNM_STYLE_BORDER_LEFT]);
+                       gnm_style_border_unref (overlay[GNM_STYLE_BORDER_TOP]);
+                       gnm_style_border_unref (overlay[GNM_STYLE_BORDER_LEFT]);
                        g_free (overlay);
                }
        }
@@ -3568,8 +3565,7 @@ gnm_xl_importer_free (GnmXLImporter *importer)
        if (importer->sst != NULL) {
                unsigned i = importer->sst_len;
                while (i-- > 0) {
-                       if (importer->sst[i].content)
-                               go_string_unref (importer->sst[i].content);
+                       go_string_unref (importer->sst[i].content);
                        go_format_unref (importer->sst[i].markup);
                }
                g_free (importer->sst);
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index 0bc9d5d..54b812b 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -4631,8 +4631,7 @@ xlsx_border_color (GsfXMLIn *xin, xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
        GnmColor *color = elem_color (xin, attrs, TRUE);
-       if (state->border_color)
-               style_color_unref (state->border_color);
+       style_color_unref (state->border_color);
        state->border_color = color;
 }
 
@@ -5284,7 +5283,7 @@ xlsx_file_open (G_GNUC_UNUSED GOFileOpener const *fo, GOIOContext *context,
        if (state.cur_style) g_object_unref (state.cur_style);
        if (state.style_accum) gnm_style_unref (state.style_accum);
        if (state.pending_rowcol_style) gnm_style_unref (state.pending_rowcol_style);
-       if (state.border_color) style_color_unref (state.border_color);
+       style_color_unref (state.border_color);
 
        workbook_set_saveinfo (state.wb, GO_FILE_FL_AUTO,
                               go_file_saver_for_id ((state.version == ECMA_376_2006) ?
diff --git a/src/dialogs/dialog-cell-format.c b/src/dialogs/dialog-cell-format.c
index 7cec7dc..c7a3864 100644
--- a/src/dialogs/dialog-cell-format.c
+++ b/src/dialogs/dialog-cell-format.c
@@ -423,8 +423,7 @@ setup_color_pickers (FormatState *state,
        w = go_gtk_builder_get_widget (state->gui, label);
        gtk_label_set_mnemonic_widget (GTK_LABEL (w), combo);
 
-       if (def_sc)
-               style_color_unref (def_sc);
+       style_color_unref (def_sc);
 
        if (picker != NULL) {
                picker->combo          = combo;
diff --git a/src/expr-name.c b/src/expr-name.c
index a2da760..bec07af 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -815,10 +815,8 @@ expr_name_unref (GnmNamedExpr *nexpr)
 
        g_return_if_fail (nexpr->scope == NULL);
 
-       if (nexpr->name) {
-               go_string_unref (nexpr->name);
-               nexpr->name = NULL;
-       }
+       go_string_unref (nexpr->name);
+       nexpr->name = NULL;
 
        if (nexpr->texpr != NULL)
                expr_name_set_expr (nexpr, NULL);
diff --git a/src/func.c b/src/func.c
index 7f84c6b..1714934 100644
--- a/src/func.c
+++ b/src/func.c
@@ -376,8 +376,7 @@ gnm_func_free (GnmFunc *func)
 
        g_free ((char *)func->name);
 
-       if (func->tdomain)
-               go_string_unref (func->tdomain);
+       go_string_unref (func->tdomain);
 
        gnm_func_clear_arg_names (func);
 
diff --git a/src/input-msg.c b/src/input-msg.c
index d182dc8..5fd70f9 100644
--- a/src/input-msg.c
+++ b/src/input-msg.c
@@ -43,14 +43,11 @@ gnm_input_msg_finalize (GObject *obj)
        GObjectClass *parent_class;
        GnmInputMsg *msg = (GnmInputMsg *)obj;
 
-       if (msg->title != NULL) {
-               go_string_unref (msg->title);
-               msg->title = NULL;
-       }
-       if (msg->msg != NULL) {
-               go_string_unref (msg->msg);
-               msg->msg = NULL;
-       }
+       go_string_unref (msg->title);
+       msg->title = NULL;
+
+       go_string_unref (msg->msg);
+       msg->msg = NULL;
 
        parent_class = g_type_class_peek (G_TYPE_OBJECT);
        parent_class->finalize (obj);
diff --git a/src/mstyle.c b/src/mstyle.c
index f966743..3112cff 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1489,8 +1489,7 @@ gnm_style_set_border (GnmStyle *style, GnmStyleElement elem,
                elem_changed (style, elem);
                elem_set (style, elem);
                elem -= MSTYLE_BORDER_TOP;
-               if (style->borders[elem])
-                       gnm_style_border_unref (style->borders[elem]);
+               gnm_style_border_unref (style->borders[elem]);
                style->borders[elem] = border;
                break;
        default:
diff --git a/src/style-border.c b/src/style-border.c
index 7bb8bdf..a2cca9c 100644
--- a/src/style-border.c
+++ b/src/style-border.c
@@ -209,8 +209,7 @@ gnm_style_border_fetch (GnmStyleBorderType           line_type,
        }
 
        if (line_type == GNM_STYLE_BORDER_NONE) {
-               if (color)
-                       style_color_unref (color);
+               style_color_unref (color);
                return gnm_style_border_ref (gnm_style_border_none ());
        }
 
@@ -222,8 +221,7 @@ gnm_style_border_fetch (GnmStyleBorderType           line_type,
        if (border_hash) {
                border = g_hash_table_lookup (border_hash, &key);
                if (border != NULL) {
-                       if (color)
-                               style_color_unref (color);
+                       style_color_unref (color);
                        return gnm_style_border_ref (border);
                }
        } else
@@ -326,10 +324,8 @@ gnm_style_border_unref (GnmBorder *border)
        /* Remove here, before we mess with the hashed fields.  */
        g_hash_table_remove (border_hash, border);
 
-       if (border->color) {
-               style_color_unref (border->color);
-               border->color = NULL;
-       }
+       style_color_unref (border->color);
+       border->color = NULL;
 
        g_free (border);
 }
diff --git a/src/style-color.c b/src/style-color.c
index f1aedbe..eb0ef9c 100644
--- a/src/style-color.c
+++ b/src/style-color.c
@@ -242,35 +242,23 @@ cb_color_leak (gpointer key, gpointer value, gpointer user_data)
 void
 gnm_color_shutdown (void)
 {
-       if (sc_black) {
-               style_color_unref (sc_black);
-               sc_black = NULL;
-       }
-
-       if (sc_white) {
-               style_color_unref (sc_white);
-               sc_white = NULL;
-       }
-
-       if (sc_grid) {
-               style_color_unref (sc_grid);
-               sc_grid = NULL;
-       }
-
-       if (sc_auto_back) {
-               style_color_unref (sc_auto_back);
-               sc_auto_back = NULL;
-       }
-
-       if (sc_auto_font) {
-               style_color_unref (sc_auto_font);
-               sc_auto_font = NULL;
-       }
-
-       if (sc_auto_pattern) {
-               style_color_unref (sc_auto_pattern);
-               sc_auto_pattern = NULL;
-       }
+       style_color_unref (sc_black);
+       sc_black = NULL;
+
+       style_color_unref (sc_white);
+       sc_white = NULL;
+
+       style_color_unref (sc_grid);
+       sc_grid = NULL;
+
+       style_color_unref (sc_auto_back);
+       sc_auto_back = NULL;
+
+       style_color_unref (sc_auto_font);
+       sc_auto_font = NULL;
+
+       style_color_unref (sc_auto_pattern);
+       sc_auto_pattern = NULL;
 
        g_hash_table_foreach (style_color_hash, cb_color_leak, NULL);
        g_hash_table_destroy (style_color_hash);
diff --git a/src/validation.c b/src/validation.c
index 86fe00d..781eec7 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -380,14 +380,12 @@ gnm_validation_unref (GnmValidation const *val)
        if (v->ref_count < 1) {
                int i;
 
-               if (v->title != NULL) {
-                       go_string_unref (v->title);
-                       v->title = NULL;
-               }
-               if (v->msg != NULL) {
-                       go_string_unref (v->msg);
-                       v->msg = NULL;
-               }
+               go_string_unref (v->title);
+               v->title = NULL;
+
+               go_string_unref (v->msg);
+               v->msg = NULL;
+
                for (i = 0 ; i < 2 ; i++)
                        dependent_managed_set_expr (&v->deps[i], NULL);
                g_free (v);
diff --git a/tools/check-gfrees b/tools/check-gfrees
index edf3a88..fc1a43d 100755
--- a/tools/check-gfrees
+++ b/tools/check-gfrees
@@ -61,28 +61,28 @@ my %exceptions =
 
                if ($lineno >= 2 &&
                    ($lines[-2] . $lines[-1]) =~
-                   /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^   
()]+)\s*(!=\s*NULL\s*)?\)\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release)\s*\(\s*\2\s*\)\s*;/)
 {
+                   /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^   
()]+)\s*(!=\s*NULL\s*)?\)\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release|(go_string|style_color|gnm_style_border)_(un)?ref)\s*\(\s*\2\s*\)\s*;/)
 {
                    print STDERR "$0: Checked $4 at $filename:$lineno\n";
                    next LINE;
                }
 
                if ($lineno >= 4 &&
                    ($lines[-4] . $lines[-3] . $lines[-2] . $lines[-1] ) =~
-                   /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^   
()]+)\s*(!=\s*NULL\s*)?\)\s*{\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release)\s*\(\s*\2\s*\)\s*;\s*\2\s*=\s*(0|NULL)\s*;\s*}/)
 {
+                   /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^   
()]+)\s*(!=\s*NULL\s*)?\)\s*{\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release|(go_string|style_color|gnm_style_border)_(un)?ref)\s*\(\s*\2\s*\)\s*;\s*\2\s*=\s*(0|NULL)\s*;\s*}/)
 {
                    print STDERR "$0: Checked $4 at $filename:$lineno\n";
                    next LINE;
                }
 
                if ($lineno >= 3 &&
                    ($lines[-3] . $lines[-2] . $lines[-1]) =~
-                   /^[^\n]*([^         
()]+)(\s*!=\s*NULL)?\s*\?\s*(g_strdup|value_dup)\s*\(\s*\1\s*\)\s*:\s*NULL/) {
+                   /^[^\n]*([^         
()]+)(\s*!=\s*NULL)?\s*\?\s*(g_strdup|value_dup|go_string_ref|style_color_ref|gnm_style_border_ref)\s*\(\s*\1\s*\)\s*:\s*NULL/)
 {
                    print STDERR "$0: Checked $3 at $filename:$lineno\n";
                    next LINE;
                }
 
                if ($lineno >= 3 &&
                    ($lines[-3] . $lines[-2] . $lines[-1]) =~
-                   /^[^\n]*(\s*NULL\s*!=\s*)([^        
()]+)\s*\?\s*(g_strdup|value_dup)\s*\(\s*\2\s*\)\s*:\s*NULL/) {
+                   /^[^\n]*(\s*NULL\s*!=\s*)([^        
()]+)\s*\?\s*(g_strdup|value_dup|go_string_ref|style_color_ref|gnm_style_border_ref)\s*\(\s*\2\s*\)\s*:\s*NULL/)
 {
                    print STDERR "$0: Checked $3 at $filename:$lineno\n";
                    next LINE;
                }


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