Check for valid column titles (non-zero-length) and valid column formats

in preference settings.

In the process of doing that, fix a memory leak (we were handing a null
pointer, rather than a pointer to the list of strings in
"column.format", to "clear_string_list()").

svn path=/trunk/; revision=3775
This commit is contained in:
Guy Harris 2001-07-22 21:50:47 +00:00
parent 0edb5d5dc8
commit 6b664c122c
3 changed files with 35 additions and 11 deletions

View File

@ -1,7 +1,7 @@
/* column.c
* Routines for handling column preferences
*
* $Id: column.c,v 1.32 2001/07/22 21:28:46 guy Exp $
* $Id: column.c,v 1.33 2001/07/22 21:50:46 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -376,7 +376,7 @@ get_column_format_from_str(gchar *str) {
}
cptr++;
}
return COL_NUMBER;
return -1; /* illegal */
}
gchar *

View File

@ -1,7 +1,7 @@
/* column_prefs.c
* Dialog box for column preferences
*
* $Id: column_prefs.c,v 1.5 2000/11/17 21:00:39 gram Exp $
* $Id: column_prefs.c,v 1.6 2001/07/22 21:50:47 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -203,6 +203,7 @@ column_sel_list_cb(GtkWidget *l, gpointer data) {
cfmt = (fmt_data *) clp->data;
title = cfmt->title;
cur_fmt = get_column_format_from_str(cfmt->fmt);
g_assert(cur_fmt != -1); /* It should always be valid */
gtk_option_menu_set_history(GTK_OPTION_MENU(fmt_m), cur_fmt);
sensitivity = TRUE;
if (clp != g_list_first(prefs.col_list))

39
prefs.c
View File

@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
* $Id: prefs.c,v 1.54 2001/07/22 21:27:54 guy Exp $
* $Id: prefs.c,v 1.55 2001/07/22 21:50:46 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -956,7 +956,7 @@ string_to_name_resolve(char *string, guint32 *name_resolve)
static int
set_pref(gchar *pref_name, gchar *value)
{
GList *col_l;
GList *col_l, *col_l_elt;
gint llen;
fmt_data *cfmt;
unsigned long int cval;
@ -999,17 +999,40 @@ set_pref(gchar *pref_name, gchar *value)
clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
/* Check to make sure all column formats are valid. */
col_l_elt = g_list_first(col_l);
while(col_l_elt) {
/* Make sure the title isn't empty. */
if (strcmp(col_l_elt->data, "") == 0) {
/* It is. */
clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
/* Go past the title. */
col_l_elt = col_l_elt->next;
/* Check the format. */
if (get_column_format_from_str(col_l_elt->data) == -1) {
/* It's not a valid column format. */
clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
/* Go past the format. */
col_l_elt = col_l_elt->next;
}
free_col_info(&prefs);
prefs.col_list = NULL;
llen = g_list_length(col_l);
prefs.num_cols = llen / 2;
col_l = g_list_first(col_l);
while(col_l) {
col_l_elt = g_list_first(col_l);
while(col_l_elt) {
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt->title = g_strdup(col_l->data);
col_l = col_l->next;
cfmt->fmt = g_strdup(col_l->data);
col_l = col_l->next;
cfmt->title = g_strdup(col_l_elt->data);
col_l_elt = col_l_elt->next;
cfmt->fmt = g_strdup(col_l_elt->data);
col_l_elt = col_l_elt->next;
prefs.col_list = g_list_append(prefs.col_list, cfmt);
}
clear_string_list(col_l);