diff --git a/main.c b/main.c index b2998eb..c2ce0b7 100644 --- a/main.c +++ b/main.c @@ -235,12 +235,22 @@ void add_command_handler(int width, int height) { } void view_command_handler(int width, int height, int index) { + // check if the index is out of bounds + if (index < 0 || index >= arrlen(todos)) { + return; + } + TodoItem item = todos[index]; // create an alert in the middle of the screen alert(item.title, width, height); } void mark_command_handler(int index) { + // check if the index is out of bounds + if (index < 0 || index >= arrlen(todos)) { + return; + } + TodoItem item = todos[index]; todo_mark_item(&item, !item.completed); @@ -252,6 +262,11 @@ void mark_command_handler(int index) { } void remove_command_handler(int index) { + // check if the index is out of bounds + if (index < 0 || index >= arrlen(todos)) { + return; + } + arrdel(todos, index); // set the dirty flag