fix index oob segfaults

This commit is contained in:
2025-04-28 02:36:14 +02:00
parent f40b4001c7
commit 3b99b87c22

15
main.c
View File

@@ -235,12 +235,22 @@ void add_command_handler(int width, int height) {
} }
void view_command_handler(int width, int height, int index) { 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]; TodoItem item = todos[index];
// create an alert in the middle of the screen // create an alert in the middle of the screen
alert(item.title, width, height); alert(item.title, width, height);
} }
void mark_command_handler(int index) { 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]; TodoItem item = todos[index];
todo_mark_item(&item, !item.completed); todo_mark_item(&item, !item.completed);
@@ -252,6 +262,11 @@ void mark_command_handler(int index) {
} }
void remove_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); arrdel(todos, index);
// set the dirty flag // set the dirty flag