aboutsummaryrefslogtreecommitdiffstats
path: root/src/todo.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-10-14 07:44:37 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2016-10-14 20:29:50 +0200
commit39d30073180aeed73ce26ca2a20be19d643e3160 (patch)
treea8569600292464f52147ec952f672c1d0b9110a7 /src/todo.c
parent9ef5fe2191c5d1d857bc4fe828c15268ba8caa90 (diff)
downloadcalcurse-39d30073180aeed73ce26ca2a20be19d643e3160.tar.gz
calcurse-39d30073180aeed73ce26ca2a20be19d643e3160.zip
Prevent segfault when all todo items are hidden
To prevent from illegal memory access, we checked whether the list of todo items is empty before performing an interactive todo item action such as flagging or removal. However, since 1a4bf2b (Add a "hide completed" view to the todo panel, 2016-01-17), it is possible to hide completed items from the todo panel. Thus, it may occur that the todo list box is empty while the list of todo items is not. To detect such situations as well, teach todo_get_item() to return NULL if the requested item does not exist. Then, instead of checking whether the todo item list is non-empty, make sure that the item returned by todo_get_item() is non-NULL when performing an action. Reported-by: Vlad Glagolev <scm@vaygr.net> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/todo.c')
-rw-r--r--src/todo.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/todo.c b/src/todo.c
index 9a6f72f..8027803 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -59,6 +59,9 @@ struct todo *todo_get_item(int item_number, int skip_completed)
else
i = LLIST_NTH(&todolist, item_number);
+ if (!i)
+ return NULL;
+
return LLIST_GET_DATA(i);
}