fix index oob segfaults
This commit is contained in:
15
main.c
15
main.c
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user