evolution-3.6.4/widgets/table/e-table-utils.c

Location Tool Test ID Function Issue
e-table-utils.c:130:15 clang-analyzer Access to field 'search' results in a dereference of a null pointer (loaded from variable 'col')
e-table-utils.c:130:15 clang-analyzer Access to field 'search' results in a dereference of a null pointer (loaded from variable 'col')
  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Chris Lahey <clahey@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include <libintl.h>		/* This file uses dgettext() but no _() */
 29 #include <string.h>
 30 
 31 #include "e-util/e-util.h"
 32 #include "e-util/e-unicode.h"
 33 
 34 #include "e-table-utils.h"
 35 #include "e-table-header-utils.h"
 36 
 37 ETableHeader *
 38 e_table_state_to_header (GtkWidget *widget,
 39                          ETableHeader *full_header,
 40                          ETableState *state)
 41 {
 42 	ETableHeader *nh;
 43 	const gint max_cols = e_table_header_count (full_header);
 44 	gint column;
 45 	GValue *val = g_new0 (GValue, 1);
 46 
 47 	g_return_val_if_fail (widget, NULL);
 48 	g_return_val_if_fail (full_header, NULL);
 49 	g_return_val_if_fail (state, NULL);
 50 
 51 	nh = e_table_header_new ();
 52 	g_value_init (val, G_TYPE_DOUBLE);
 53 	g_value_set_double (val, e_table_header_width_extras (widget));
 54 	g_object_set_property (G_OBJECT (nh), "width_extras", val);
 55 	g_free (val);
 56 
 57 	for (column = 0; column < state->col_count; column++) {
 58 		gint col;
 59 		gdouble expansion;
 60 		ETableCol *table_col;
 61 
 62 		col = state->columns[column];
 63 		expansion = state->expansions[column];
 64 
 65 		if (col >= max_cols)
 66 			continue;
 67 
 68 		table_col = e_table_header_get_column (full_header, col);
 69 
 70 		if (expansion >= -1)
 71 			table_col->expansion = expansion;
 72 
 73 		e_table_header_add_column (nh, table_col, -1);
 74 	}
 75 
 76 	return nh;
 77 }
 78 
 79 static ETableCol *
 80 et_col_spec_to_col (ETableColumnSpecification *col_spec,
 81                     ETableExtras *ete,
 82                     const gchar *domain)
 83 {
 84 	ETableCol *col = NULL;
 85 	ECell *cell = NULL;
 86 	GCompareDataFunc compare = NULL;
 87 	ETableSearchFunc search = NULL;
 88 
 89 	if (col_spec->cell)
 90 		cell = e_table_extras_get_cell (ete, col_spec->cell);
 91 	if (col_spec->compare)
 92 		compare = e_table_extras_get_compare (ete, col_spec->compare);
 93 	if (col_spec->search)
 94 		search = e_table_extras_get_search (ete, col_spec->search);
 95 
 96 	if (cell && compare) {
 97 		gchar *title = dgettext (domain, col_spec->title);
 98 
 99 		title = g_strdup (title);
100 
101 		if (col_spec->pixbuf && *col_spec->pixbuf) {
102 			const gchar *icon_name;
103 
104 			icon_name = e_table_extras_get_icon_name (
105 				ete, col_spec->pixbuf);
106 			if (icon_name != NULL) {
107 				col = e_table_col_new (
108 					col_spec->model_col,
109 					title, icon_name,
110 					col_spec->expansion,
111 					col_spec->minimum_width,
112 					cell, compare,
113 					col_spec->resizable,
114 					col_spec->disabled,
115 					col_spec->priority);
116 			}
117 		}
118 
119 		if (col == NULL && col_spec->title && *col_spec->title) {
120 			col = e_table_col_new (
121 				col_spec->model_col, title, NULL,
122 				col_spec->expansion,
123 				col_spec->minimum_width,
124 				cell, compare,
125 				col_spec->resizable,
126 				col_spec->disabled,
127 				col_spec->priority);
128 		}
129 
130 		col->search = search;
Access to field 'search' results in a dereference of a null pointer (loaded from variable 'col')
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

Access to field 'search' results in a dereference of a null pointer (loaded from variable 'col')
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

131 if (col_spec->sortable && !strcmp (col_spec->sortable, "false")) 132 col->sortable = FALSE; 133 else 134 col->sortable = TRUE; 135 g_free (title); 136 } 137 if (col && col_spec->compare_col != col_spec->model_col) 138 g_object_set ( 139 col, 140 "compare_col", col_spec->compare_col, 141 NULL); 142 return col; 143 } 144 145 ETableHeader * 146 e_table_spec_to_full_header (ETableSpecification *spec, 147 ETableExtras *ete) 148 { 149 ETableHeader *nh; 150 gint column; 151 152 g_return_val_if_fail (spec, NULL); 153 g_return_val_if_fail (ete, NULL); 154 155 nh = e_table_header_new (); 156 157 for (column = 0; spec->columns[column]; column++) { 158 ETableCol *col = et_col_spec_to_col ( 159 spec->columns[column], ete, spec->domain); 160 161 if (col) { 162 e_table_header_add_column (nh, col, -1); 163 g_object_unref (col); 164 } 165 } 166 167 return nh; 168 } 169 170 static gboolean 171 check_col (ETableCol *col, 172 gpointer user_data) 173 { 174 return col->search ? TRUE : FALSE; 175 } 176 177 ETableCol * 178 e_table_util_calculate_current_search_col (ETableHeader *header, 179 ETableHeader *full_header, 180 ETableSortInfo *sort_info, 181 gboolean always_search) 182 { 183 gint i; 184 gint count; 185 ETableCol *col = NULL; 186 187 count = e_table_sort_info_grouping_get_count (sort_info); 188 189 for (i = 0; i < count; i++) { 190 ETableSortColumn column; 191 192 column = e_table_sort_info_grouping_get_nth (sort_info, i); 193 194 col = e_table_header_get_column (full_header, column.column); 195 196 if (col && col->search) 197 break; 198 199 col = NULL; 200 } 201 202 if (col == NULL) { 203 count = e_table_sort_info_sorting_get_count (sort_info); 204 for (i = 0; i < count; i++) { 205 ETableSortColumn column; 206 207 column = e_table_sort_info_sorting_get_nth (sort_info, i); 208 209 col = e_table_header_get_column (full_header, column.column); 210 211 if (col && col->search) 212 break; 213 214 col = NULL; 215 } 216 } 217 218 if (col == NULL && always_search) { 219 col = e_table_header_prioritized_column_selected (header, check_col, NULL); 220 } 221 222 return col; 223 }