From 040e81014e1d79f0348031f6de8954c4411496c9 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 17 May 2016 22:46:33 -0400 Subject: [PATCH] limit list index to valid range --- 4ed_file_view.cpp | 15 ++++++++------- 4ed_gui.cpp | 11 ++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index ee28ff29..45a512c2 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1000,7 +1000,7 @@ undo_stack_pop(Edit_Stack *stack){ } internal void -file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ +file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ Edit_Stack *redo = &file->state.undo.redo; if (step.child_count == 0){ @@ -3689,17 +3689,17 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } gui_do_text_field(target, message, hdir->string); - + view->current_scroll = &view->gui_scroll; gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll); gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, 9.f * view->font_height); - + id.id[0] = (u64)(hdir) + 1; - + if (gui_begin_list(target, id, view->list_i, 0, &update)){ gui_standard_list(target, id, &keys, &view->list_i, &update); } - + { begin_exhaustive_loop(&loop, hdir); for (i = 0; i < loop.count; ++i){ @@ -3707,7 +3707,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (file_info.name_match){ id.id[0] = (u64)(file_info.info); - if (gui_do_file_option(target, id, file_info.info->filename, file_info.is_folder, file_info.message)){ + if (gui_do_file_option(target, id, file_info.info->filename, + file_info.is_folder, file_info.message)){ if (file_info.is_folder){ set_last_folder(&hdir->string, file_info.info->filename, '/'); do_new_directory = 1; @@ -3729,7 +3730,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (do_new_directory){ hot_directory_reload(system, hdir, &models->working_set); } - + gui_end_scrollable(target); }break; diff --git a/4ed_gui.cpp b/4ed_gui.cpp index ed971051..9dde629d 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -142,6 +142,7 @@ struct GUI_Target{ GUI_id auto_hot; GUI_id hover; + // TODO(allen): Can we remove original yet? GUI_Scroll_Vars scroll_original; GUI_Scroll_Vars scroll_updated; @@ -490,7 +491,15 @@ gui_begin_list(GUI_Target *target, GUI_id id, i32 list_i, b32 activate_item, GUI } if (result){ - gui_fill_item_update(update, target, h, active); + if (list_i < 0){ + gui_fill_item_update(update, target, h, active, 0); + } + else if (list_i >= target->list_max){ + gui_fill_item_update(update, target, h, active, target->list_max - 1); + } + else{ + gui_fill_item_update(update, target, h, active); + } target->animating = 1; }