Fix out-of-bounds memory access
Do not try to access freed day items. This also fixes unexpected selection changes after modifying appointments or events. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
@@ -695,20 +695,25 @@ int day_paste_item(struct day_item *p, long date)
|
||||
}
|
||||
|
||||
/* Returns the position corresponding to a given item. */
|
||||
int day_get_position(struct day_item *needle)
|
||||
int day_get_position_by_aptev_ptr(union aptev_ptr aptevp)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
VECTOR_FOREACH(&day_items, n) {
|
||||
struct day_item *p = VECTOR_NTH(&day_items, n);
|
||||
/* Compare pointers. */
|
||||
if (p->item.ev == needle->item.ev)
|
||||
if (p->item.ev == aptevp.ev)
|
||||
return n;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int day_get_position(struct day_item *needle)
|
||||
{
|
||||
return day_get_position_by_aptev_ptr(needle->item);
|
||||
}
|
||||
|
||||
/* Returns a structure containing the selected item. */
|
||||
struct day_item *day_get_item(int item_number)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user