Skip to content

Commit

Permalink
Handle the case of reduction of the number of view directory types.
Browse files Browse the repository at this point in the history
Previously it was leading to a segfault.
  • Loading branch information
Laurent Monin committed Apr 25, 2008
1 parent 856f0b2 commit 74182a1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ LayoutWindow *layout_new_with_geometry(const gchar *path, gint popped, gint hidd

layout_config_parse(options->layout.style, options->layout.order,
&lw->dir_location, &lw->file_location, &lw->image_location);
lw->dir_view_type = options->layout.dir_view_type;
lw->dir_view_type = CLAMP(options->layout.dir_view_type, 0, VIEW_DIR_TYPES_COUNT - 1);
lw->icon_view = options->layout.view_as_icons;

/* divider positions */
Expand Down
2 changes: 1 addition & 1 deletion src/layout_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ void layout_actions_setup(LayoutWindow *lw)
menu_split_radio_entries, G_N_ELEMENTS(menu_split_radio_entries),
0, G_CALLBACK(layout_menu_split_cb), lw);
gtk_action_group_add_radio_actions(lw->action_group,
menu_view_dir_radio_entries, G_N_ELEMENTS(menu_view_dir_radio_entries),
menu_view_dir_radio_entries, VIEW_DIR_TYPES_COUNT,
0, G_CALLBACK(layout_menu_view_dir_as_cb), lw);

lw->ui_manager = gtk_ui_manager_new();
Expand Down
4 changes: 3 additions & 1 deletion src/view_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static void vd_destroy_cb(GtkWidget *widget, gpointer data)

ViewDir *vd_new(DirViewType type, const gchar *path)
{
g_assert(VIEW_DIR_TYPES_COUNT <= G_N_ELEMENTS(menu_view_dir_radio_entries));

ViewDir *vd = g_new0(ViewDir, 1);

vd->path = NULL;
Expand Down Expand Up @@ -618,7 +620,7 @@ GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);

for (i = 0; i < G_N_ELEMENTS(menu_view_dir_radio_entries); i++)
for (i = 0; i < VIEW_DIR_TYPES_COUNT; i++)
{
item = menu_item_add_check(submenu, _(menu_view_dir_radio_entries[i].label),
(vd->type == menu_view_dir_radio_entries[i].value),
Expand Down
3 changes: 2 additions & 1 deletion src/view_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ enum {
DIR_COLUMN_COUNT
};

extern GtkRadioActionEntry menu_view_dir_radio_entries[2];
#define VIEW_DIR_TYPES_COUNT 1
extern GtkRadioActionEntry menu_view_dir_radio_entries[VIEW_DIR_TYPES_COUNT];

ViewDir *vd_new(DirViewType type, const gchar *path);

Expand Down

0 comments on commit 74182a1

Please sign in to comment.