Commit b097aebe authored by Morten Welinder's avatar Morten Welinder

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.
parent 9f01992d
......@@ -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");
......
......@@ -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);
......
......@@ -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) ?
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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:
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment