Skip to content

Commit

Permalink
Utils: fix several crashes with event processing (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Noël authored and danirabbit committed Nov 26, 2019
1 parent 08e4d01 commit a11723e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
23 changes: 7 additions & 16 deletions core/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,23 @@ namespace Maya.Util {
}

public bool calcomp_is_on_day (ECal.Component comp, GLib.DateTime day) {
ECal.ComponentDateTime start_dt;
ECal.ComponentDateTime end_dt;

#if E_CAL_2_0
start_dt = comp.get_dtstart ();
end_dt = comp.get_dtend ();
unowned ICal.Timezone system_timezone = ECal.util_get_system_timezone ();
#else
comp.get_dtstart (out start_dt);
comp.get_dtend (out end_dt);
unowned ICal.Timezone system_timezone = ECal.Util.get_system_timezone ();
#endif

var stripped_time = new DateTime.local (day.get_year (), day.get_month (), day.get_day_of_month (), 0, 0, 0);

var selected_date_unix = stripped_time.to_unix ();
var selected_date_unix_next = stripped_time.add_days (1).to_unix ();
time_t start_unix;
time_t end_unix;

/* We want to be relative to the local timezone */
#if E_CAL_2_0
start_unix = start_dt.get_value ().as_timet_with_zone (ECal.util_get_system_timezone ());
end_unix = end_dt.get_value ().as_timet_with_zone (ECal.util_get_system_timezone ());
#else
start_unix = (*start_dt.value).as_timet_with_zone (ECal.Util.get_system_timezone ());
end_unix = (*end_dt.value).as_timet_with_zone (ECal.Util.get_system_timezone ());
#endif
unowned ICal.Component? icomp = comp.get_icalcomponent ();
ICal.Time? start_time = icomp.get_dtstart ();
ICal.Time? end_time = icomp.get_dtend ();
time_t start_unix = start_time.as_timet_with_zone (system_timezone);
time_t end_unix = end_time.as_timet_with_zone (system_timezone);

/* If the selected date is inside the event */
if (start_unix < selected_date_unix && selected_date_unix_next < end_unix) {
Expand Down
5 changes: 5 additions & 0 deletions data/io.elementary.calendar.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
</p>
</description>
<releases>
<release version="5.0.2" date="2019-11-25" urgency="medium">
<description>
<p>Fix potential crash when loading events with no start or end time</p>
</description>
</release>
<release version="5.0.1" date="2019-11-25" urgency="medium">
<description>
<p>Make agenda pane fill the whole space</p>
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/EventMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Maya.EventMenu : Gtk.Menu {
}

private void add_exception () {
ECal.ComponentDateTime dtstart;
ECal.ComponentDateTime? dtstart;
GLib.SList<ECal.ComponentDateTime?>? exdate_list;
#if E_CAL_2_0
dtstart = comp.get_dtstart ();
Expand All @@ -76,7 +76,7 @@ public class Maya.EventMenu : Gtk.Menu {
#else
comp.get_dtstart (out dtstart);
comp.get_exdate_list (out exdate_list);
exdate_list.append (dtstart);
exdate_list.append ((owned) dtstart);
comp.set_exdate_list (exdate_list);
#endif

Expand Down
44 changes: 24 additions & 20 deletions vapi/libecal-1.2.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -131,42 +131,42 @@ namespace ECal {
public string get_as_string ();
public void get_attachment_list (out GLib.SList<string> attachment_list);
public void get_attendee_list (out GLib.SList<ECal.ComponentAttendee?> attendee_list);
public void get_categories (out string categories);
public void get_categories (out string? categories);
public void get_categories_list (out GLib.SList<string> categ_list);
public void get_classification (out ECal.ComponentClassification classif);
public void get_classification (out ECal.ComponentClassification? classif);
public void get_comment_list (out GLib.SList<ECal.ComponentText> text_list);
public void get_completed (out ICal.Time t);
public void get_completed (out ICal.Time? t);
public void get_contact_list (out GLib.SList<ECal.ComponentText> text_list);
public void get_created (out ICal.Time t);
public void get_created (out ICal.Time? t);
public void get_description_list (out GLib.SList<ECal.ComponentText> text_list);
public void get_dtend (out ECal.ComponentDateTime dt);
public void get_dtstamp (out ICal.Time t);
public void get_dtstart (out ECal.ComponentDateTime dt);
public void get_due (out ECal.ComponentDateTime dt);
public void get_dtend (out ECal.ComponentDateTime? dt);
public void get_dtstamp (out ICal.Time? t);
public void get_dtstart (out ECal.ComponentDateTime? dt);
public void get_due (out ECal.ComponentDateTime? dt);
public void get_exdate_list (out GLib.SList<ECal.ComponentDateTime> exdate_list);
public void get_exrule_list (out GLib.SList<ICal.Recurrence> recur_list);
public void get_exrule_property_list (out GLib.SList<ECal.ComponentRange> recur_list);
public void get_geo (out ICal.Geo geo);
public void get_geo (out ICal.Geo? geo);
public unowned ICal.Component get_icalcomponent ();
public ECal.ComponentId get_id ();
public void get_last_modified (out ICal.Time t);
public void get_location (out string location);
public void get_last_modified (out ICal.Time? t);
public void get_location (out string? location);
public int get_num_attachments ();
public void get_organizer (out ECal.ComponentOrganizer organizer);
public void get_percent (out int percent);
public void get_organizer (out ECal.ComponentOrganizer? organizer);
public void get_percent (out int? percent);
public int get_percent_as_int ();
public void get_priority (out int priority);
public void get_priority (out int? priority);
public void get_rdate_list (out GLib.SList<ECal.ComponentPeriod> period_list);
public void get_recurid (out ECal.ComponentRange recur_id);
public void get_recurid (out ECal.ComponentRange? recur_id);
public string get_recurid_as_string ();
public void get_rrule_list (out GLib.SList<ICal.Recurrence> recur_list);
public void get_rrule_property_list (out GLib.SList<ECal.ComponentRange> recur_list);
public void get_sequence (out int sequence);
public void get_status (out ICal.PropertyStatus status);
public void get_sequence (out int? sequence);
public void get_status (out ICal.PropertyStatus? status);
public ECal.ComponentText get_summary ();
public void get_transparency (out ECal.ComponentTransparency transp);
public void get_transparency (out ECal.ComponentTransparency? transp);
public void get_uid (out string uid);
public void get_url (out string url);
public void get_url (out string? url);
public ECal.ComponentVType get_vtype ();
public bool has_alarms ();
public bool has_attachments ();
Expand Down Expand Up @@ -309,8 +309,12 @@ namespace ECal {
}
[CCode (cheader_filename = "libecal/libecal.h", free_function = "e_cal_component_free_datetime")]
public struct ComponentDateTime {
public ICal.Time* value;
public ICal.Time? value;
public weak string tzid;
[CCode (cname = "_vala_e_cal_component_get_value")]
public unowned ICal.Time? get_value () {
return value;
}
}
[CCode (cheader_filename = "libecal/libecal.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "e_cal_component_id_get_type ()")]
[Compact]
Expand Down
2 changes: 1 addition & 1 deletion vapi/libical.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ namespace ICal {
[CCode (cname = "is_date")]
public int _is_date;
public int is_daylight;
public weak ICal.Timezone zone;
public weak ICal.Timezone? zone;
[CCode (cname = "icaltime_today", has_construct_function = false)]
public ICal.Time.today ();
[CCode (cname = "icaltime_from_day_of_year", has_construct_function = false)]
Expand Down

0 comments on commit a11723e

Please sign in to comment.