From 3b99b87c228f1aa1022b5cb30d22214bc23fd79e Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Mon, 28 Apr 2025 02:36:14 +0200 Subject: [PATCH] fix index oob segfaults --- main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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