My adaptation of patch https://bugzilla.gnome.org/attachment.cgi?id=161009

From: Thomas Mittelstaedt <tmstaedt@t-mittelstaedt.de>

In the stg series, there is an earlier fix for issue 607257, remove
that one!!
---

 calendar/gui/e-cal-list-view.c               |    3 
 calendar/gui/e-calendar-view.c               |   54 ++++-
 calendar/gui/e-calendar-view.h               |    9 +
 calendar/gui/e-day-view-main-item.c          |   12 +
 calendar/gui/e-day-view-top-item.c           |   13 +
 calendar/gui/e-day-view.c                    |  302 ++++++++++++++++++++++++--
 calendar/gui/e-week-view-event-item.c        |   43 ++++
 calendar/gui/e-week-view.c                   |  153 +++++++++++++
 calendar/gui/print.c                         |    9 +
 plugins/groupwise-features/process-meeting.c |   16 +
 10 files changed, 575 insertions(+), 39 deletions(-)


diff --git a/calendar/gui/e-cal-list-view.c b/calendar/gui/e-cal-list-view.c
index d077139..ad37860 100644
--- a/calendar/gui/e-cal-list-view.c
+++ b/calendar/gui/e-cal-list-view.c
@@ -432,6 +432,9 @@ e_cal_list_view_get_selected_time_range (ECalendarView *cal_view, time_t *start_
 		ECalComponentDateTime dtstart, dtend;
 		ECalComponent *comp;
 
+		if (!is_comp_data_valid (event))
+			return FALSE;
+
 		comp = e_cal_component_new ();
 		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 		if (start_time) {
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index 5546457..141f746 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -806,7 +806,7 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view)
 	for (l = selected; l != NULL; l = l->next) {
 		event = (ECalendarViewEvent *) l->data;
 
-		if (event) {
+		if (event && is_comp_data_valid (event)) {
 			e_cal_util_add_timezones_from_component (vcal_comp, event->comp_data->icalcomp);
 
 			add_related_timezones (vcal_comp, event->comp_data->icalcomp, event->comp_data->client);
@@ -816,6 +816,9 @@ e_calendar_view_copy_clipboard (ECalendarView *cal_view)
 	for (l = selected; l != NULL; l = l->next) {
 		event = (ECalendarViewEvent *) l->data;
 
+		if (!is_comp_data_valid (event))
+			continue;
+		
 		new_icalcomp = icalcomponent_new_clone (event->comp_data->icalcomp);
 
 		/* remove RECURRENCE-IDs from copied objects */
@@ -1023,6 +1026,9 @@ delete_event (ECalendarView *cal_view, ECalendarViewEvent *event)
 	gboolean  delete = FALSE;
 	GError *error = NULL;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 	vtype = e_cal_component_get_vtype (comp);
@@ -1144,6 +1150,9 @@ e_calendar_view_delete_selected_occurrence (ECalendarView *cal_view)
 	if (!selected)
 		return;
 	event = (ECalendarViewEvent *) selected->data;
+	if (!is_comp_data_valid (event))
+ 		return;
+	
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 	vtype = e_cal_component_get_vtype (comp);
@@ -1619,6 +1628,9 @@ on_forward (EPopup *ep, EPopupItem *pitem, gpointer data)
 		ECalComponent *comp;
 		ECalendarViewEvent *event = (ECalendarViewEvent *) selected->data;
 
+		if (!is_comp_data_valid (event))
+			return;
+
 		comp = e_cal_component_new ();
 		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 		itip_send_comp (E_CAL_COMPONENT_METHOD_PUBLISH, comp, event->comp_data->client, NULL, NULL, NULL, TRUE, FALSE);
@@ -1907,7 +1919,7 @@ e_calendar_view_open_event (ECalendarView *cal_view)
 	selected = e_calendar_view_get_selected_events (cal_view);
 	if (selected) {
 		ECalendarViewEvent *event = (ECalendarViewEvent *) selected->data;
-		if (event)
+		if (event && is_comp_data_valid (event))
 			e_calendar_view_edit_appointment (cal_view, event->comp_data->client,
 					event->comp_data->icalcomp, icalcomponent_get_first_property(event->comp_data->icalcomp, ICAL_ATTENDEE_PROPERTY) != NULL);
 
@@ -2385,6 +2397,9 @@ e_calendar_view_get_tooltips (ECalendarViewEventData *data)
 	default_zone = e_calendar_view_get_timezone  (data->cal_view);
 	pevent = data->get_view_event (data->cal_view, data->day, data->event_num);
 
+	if (!is_comp_data_valid (pevent))
+		return FALSE;
+
 	client = pevent->comp_data->client;
 
 	clone_comp = icalcomponent_new_clone (pevent->comp_data->icalcomp);
@@ -2707,3 +2722,38 @@ get_today_background (const GdkColor base_background)
 	return res;
 }
 
+gboolean
+is_comp_data_valid_func (ECalendarViewEvent *event, const gchar *location)
+{
+	g_return_val_if_fail (location != NULL, FALSE);
+
+	if (!event) {
+		g_warning ("%s: event is NULL", location);
+		return FALSE;
+	}
+
+	if (!event->comp_data) {
+		g_warning ("%s: event's (%p) comp_data is NULL", location, event);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+gboolean
+is_array_index_in_bounds_func (GArray *array, gint index, const gchar *location)
+{
+	g_return_val_if_fail (location != NULL, FALSE);
+
+	if (!array) {
+		g_warning ("%s: array is NULL", location);
+		return FALSE;
+	}
+
+	if (index < 0 || index >= array->len) {
+		g_warning ("%s: index %d is out of bounds [0,%d) at array %p", location, index, array->len, array);
+		return FALSE;
+	}
+
+	return TRUE;
+}
diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h
index ae0703a..22ad127 100644
--- a/calendar/gui/e-calendar-view.h
+++ b/calendar/gui/e-calendar-view.h
@@ -78,6 +78,15 @@ typedef struct {
 	E_CALENDAR_VIEW_EVENT_FIELDS
 } ECalendarViewEvent;
 
+/* checks if event->comp_data is not NULL, returns FALSE when it is and prints a warning on a console */
+gboolean is_comp_data_valid_func (ECalendarViewEvent *event, const gchar *location);
+#define is_comp_data_valid(_event) is_comp_data_valid_func ((ECalendarViewEvent *) (_event), G_STRFUNC)
+
+/* checks if index is within bounds for the array; returns FALSE when not, and prints a warning on a console */
+gboolean is_array_index_in_bounds_func (GArray *array, gint index, const gchar *location);
+#define is_array_index_in_bounds(_array, _index) is_array_index_in_bounds_func (_array, _index, G_STRFUNC)
+
+
 typedef struct _ECalendarView        ECalendarView;
 typedef struct _ECalendarViewClass   ECalendarViewClass;
 typedef struct _ECalendarViewPrivate ECalendarViewPrivate;
diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c
index c211a45..51a7fdb 100644
--- a/calendar/gui/e-day-view-main-item.c
+++ b/calendar/gui/e-day-view-main-item.c
@@ -454,6 +454,9 @@ e_day_view_main_item_draw_events_in_vbars (EDayViewMainItem *dvmitem,
 	for (event_num = 0; event_num < day_view->events[day]->len; event_num++) {
 		event = &g_array_index (day_view->events[day], EDayViewEvent, event_num);
 
+		if (!is_comp_data_valid (event))
+ 			continue;
+		
 		/* We can skip the events in the first column since they will
 		   draw over this anyway. */
 		if (event->num_columns > 0 && event->start_row_or_col == 0) {
@@ -519,6 +522,9 @@ e_day_view_main_item_draw_long_events_in_vbars (EDayViewMainItem *dvmitem,
 		gboolean first = TRUE;
 		event = &g_array_index (day_view->long_events, EDayViewEvent, event_num);
 
+		if (!is_comp_data_valid (event))
+			continue;
+
 		/* If the event is TRANSPARENT, skip it. */
 		if (icalcomp_is_transparent (event->comp_data->icalcomp)) {
 			continue;
@@ -672,9 +678,15 @@ e_day_view_main_item_draw_day_event (EDayViewMainItem *dvmitem,
 
 	font_options = get_font_options ();
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* Fill in the event background. Note that for events in the first
 	   column of the day, we might not want to paint over the vertical bar,
 	   since that is used for multiple events. But then you can't see
diff --git a/calendar/gui/e-day-view-top-item.c b/calendar/gui/e-day-view-top-item.c
index 6ebbde4..6cfd7bc 100644
--- a/calendar/gui/e-day-view-top-item.c
+++ b/calendar/gui/e-day-view-top-item.c
@@ -406,9 +406,15 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem,
 						 &item_w, &item_h))
 		return;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+	
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+ 		return;
+		
 	style = gtk_widget_get_style (GTK_WIDGET (day_view));
 	gc = day_view->main_gc;
 	fg_gc = style->fg_gc[GTK_STATE_NORMAL];
@@ -747,8 +753,15 @@ e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem,
 	if (h % 2 == 0)
 		c1--;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
 	cairo_save (cr);
 	/* Fill it in. */
 	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)),
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index ed83c9d..0d52738 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -1240,7 +1240,7 @@ e_day_view_get_text_color (EDayView *day_view, EDayViewEvent *event, GtkWidget *
 	green = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].green;
 	blue = day_view->colors[E_DAY_VIEW_COLOR_EVENT_BACKGROUND].blue;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
+	if (is_comp_data_valid (event) && gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data),
 	     &bg_color)) {
                 GdkColormap *colormap;
 		colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view));
@@ -1714,6 +1714,9 @@ e_day_view_foreach_event_with_uid (EDayView *day_view,
 			event = &g_array_index (day_view->events[day],
 						EDayViewEvent, event_num);
 
+			if (!is_comp_data_valid (event))
+				continue;
+
 			u = icalcomponent_get_uid (event->comp_data->icalcomp);
 			if (uid && !strcmp (uid, u)) {
 				if (!(*callback) (day_view, day, event_num, data))
@@ -1728,6 +1731,9 @@ e_day_view_foreach_event_with_uid (EDayView *day_view,
 		event = &g_array_index (day_view->long_events,
 					EDayViewEvent, event_num);
 
+		if (!is_comp_data_valid (event))
+			continue;
+
 		u = icalcomponent_get_uid (event->comp_data->icalcomp);
 		if (u && !strcmp (uid, u)) {
 			if (!(*callback) (day_view, E_DAY_VIEW_LONG_EVENT, event_num, data))
@@ -1749,12 +1755,19 @@ e_day_view_remove_event_cb (EDayView *day_view,
 		 day, event_num);
 #endif
 
-	if (day == E_DAY_VIEW_LONG_EVENT)
+	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return TRUE;
+
 		event = &g_array_index (day_view->long_events,
 					EDayViewEvent, event_num);
-	else
+	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return TRUE;
+
 		event = &g_array_index (day_view->events[day],
 					EDayViewEvent, event_num);
+	}
 
 	if (!event)
 		return TRUE;
@@ -1774,7 +1787,8 @@ e_day_view_remove_event_cb (EDayView *day_view,
 	if (event->canvas_item)
 		gtk_object_destroy (GTK_OBJECT (event->canvas_item));
 
-	e_cal_model_free_component_data (event->comp_data);
+	if (is_comp_data_valid (event))
+		e_cal_model_free_component_data (event->comp_data);
 	event->comp_data = NULL;
 
 	if (day == E_DAY_VIEW_LONG_EVENT) {
@@ -1798,6 +1812,9 @@ set_text_as_bold (EDayViewEvent *event)
 	gchar *address;
 	ECalComponentAttendee *at = NULL;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 	address = itip_get_comp_attendee (comp, event->comp_data->client);
@@ -1836,10 +1853,13 @@ e_day_view_update_event_label (EDayView *day_view,
 	gchar *text;
 	gint interval;
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent, event_num);
 
 	/* If the event isn't visible just return. */
-	if (!event->canvas_item)
+	if (!event->canvas_item || !is_comp_data_valid (event))
 		return;
 
 	summary = icalcomponent_get_summary (event->comp_data->icalcomp);
@@ -1887,11 +1907,14 @@ e_day_view_update_long_event_label (EDayView *day_view,
 	const gchar *summary;
 	gboolean free_text = FALSE;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
 	/* If the event isn't visible just return. */
-	if (!event->canvas_item)
+	if (!event->canvas_item || !is_comp_data_valid (event))
 		return;
 
 	summary = e_calendar_view_get_icalcomponent_summary (event->comp_data->client, event->comp_data->icalcomp, &free_text);
@@ -1976,6 +1999,9 @@ e_day_view_find_event_from_uid (EDayView *day_view,
 			event = &g_array_index (day_view->events[day],
 						EDayViewEvent, event_num);
 
+			if (!is_comp_data_valid (event))
+				continue;
+
 			if (event->comp_data->client != client)
 				continue;
 
@@ -2004,6 +2030,9 @@ e_day_view_find_event_from_uid (EDayView *day_view,
 		event = &g_array_index (day_view->long_events,
 					EDayViewEvent, event_num);
 
+		if (!is_comp_data_valid (event))
+			continue;
+
 		if (event->comp_data->client != client)
 			continue;
 
@@ -3069,6 +3098,9 @@ e_day_view_on_long_event_button_press (EDayView		*day_view,
 	} else if (event->button == 3) {
 		EDayViewEvent *e;
 
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return TRUE;
+
 		e = &g_array_index (day_view->long_events, EDayViewEvent, event_num);
 
 		e_day_view_set_selected_time_range_in_top_visible (day_view, e->start, e->end);
@@ -3107,6 +3139,9 @@ e_day_view_on_event_button_press (EDayView	  *day_view,
 	} else if (event->button == 3) {
 		EDayViewEvent *e;
 
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return TRUE;
+
 		e = &g_array_index (day_view->events[day], EDayViewEvent, event_num);
 
 		e_day_view_set_selected_time_range_visible (day_view, e->start, e->end);
@@ -3131,9 +3166,15 @@ e_day_view_on_long_event_click (EDayView *day_view,
 	gint start_day, end_day, day;
 	gint item_x, item_y, item_w, item_h;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* Ignore clicks on the EText while editing. */
 	if (pos == E_CALENDAR_VIEW_POS_EVENT
 	    && E_TEXT (event->canvas_item)->editing) {
@@ -3204,9 +3245,15 @@ e_day_view_on_event_click (EDayView *day_view,
 	EDayViewEvent *event;
 	gint tmp_day, row, start_row;
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* Ignore clicks on the EText while editing. */
 	if (pos == E_CALENDAR_VIEW_POS_EVENT
 	    && E_TEXT (event->canvas_item)->editing) {
@@ -3330,12 +3377,22 @@ e_day_view_on_event_double_click (EDayView *day_view,
 	EDayViewEvent *event;
 	icalproperty *attendee_prop = NULL;
 
-	if (day == -1)
+	if (day == -1) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
-	else
+	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
+	}
+
+	if (!is_comp_data_valid (event))
+		return;
 
 	attendee_prop = icalcomponent_get_first_property (event->comp_data->icalcomp, ICAL_ATTENDEE_PROPERTY);
 
@@ -3390,23 +3447,37 @@ e_day_view_get_selected_events (ECalendarView *cal_view)
 	g_return_val_if_fail (E_IS_DAY_VIEW (day_view), NULL);
 
 	if (day_view->editing_event_num != -1) {
-		if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT)
+		if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) {
+			if (!is_array_index_in_bounds (day_view->long_events, day_view->editing_event_num))
+				return NULL;
+
 			event = &g_array_index (day_view->long_events,
 						EDayViewEvent,
 						day_view->editing_event_num);
-		else
+		} else {
+			if (!is_array_index_in_bounds (day_view->events[day_view->editing_event_day], day_view->editing_event_num))
+				return NULL;
+
 			event = &g_array_index (day_view->events[day_view->editing_event_day],
 						EDayViewEvent,
 						day_view->editing_event_num);
+		}
 	} else if (day_view->popup_event_num != -1) {
-		if (day_view->popup_event_day == E_DAY_VIEW_LONG_EVENT)
+		if (day_view->popup_event_day == E_DAY_VIEW_LONG_EVENT) {
+			if (!is_array_index_in_bounds (day_view->long_events, day_view->popup_event_num))
+				return NULL;
+
 			event = &g_array_index (day_view->long_events,
 						EDayViewEvent,
 						day_view->popup_event_num);
-		else
+		} else {
+			if (!is_array_index_in_bounds (day_view->events[day_view->popup_event_day], day_view->popup_event_num))
+				return NULL;
+
 			event = &g_array_index (day_view->events[day_view->popup_event_day],
 						EDayViewEvent,
 						day_view->popup_event_num);
+		}
 	}
 
 	if (event)
@@ -3554,9 +3625,13 @@ e_day_view_on_top_canvas_motion (GtkWidget *widget,
 	pos = e_day_view_convert_position_in_top_canvas (day_view,
 							 canvas_x, canvas_y,
 							 &day, &event_num);
-	if (event_num != -1)
+	if (event_num != -1) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return FALSE;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
+	}
 
 	if (day_view->selection_is_being_dragged) {
 		e_day_view_update_selection (day_view, day, -1);
@@ -3569,9 +3644,15 @@ e_day_view_on_top_canvas_motion (GtkWidget *widget,
 	} else if (day_view->pressed_event_day == E_DAY_VIEW_LONG_EVENT) {
 		GtkTargetList *target_list;
 
+		if (!is_array_index_in_bounds (day_view->long_events, day_view->pressed_event_num))
+			return FALSE;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					day_view->pressed_event_num);
 
+		if (!is_comp_data_valid (event))
+			return FALSE;
+
 		if (!e_cal_util_component_has_recurrences (event->comp_data->icalcomp)
 		    && (abs (canvas_x - day_view->drag_event_x)
 			> E_DAY_VIEW_DRAG_START_OFFSET
@@ -3598,7 +3679,7 @@ e_day_view_on_top_canvas_motion (GtkWidget *widget,
 		cursor = day_view->normal_cursor;
 
 		/* Recurring events can't be resized. */
-		if (event && !e_cal_util_component_has_recurrences (event->comp_data->icalcomp)) {
+		if (event && is_comp_data_valid (event) && !e_cal_util_component_has_recurrences (event->comp_data->icalcomp)) {
 			switch (pos) {
 			case E_CALENDAR_VIEW_POS_LEFT_EDGE:
 			case E_CALENDAR_VIEW_POS_RIGHT_EDGE:
@@ -3652,9 +3733,13 @@ e_day_view_on_main_canvas_motion (GtkWidget *widget,
 							  canvas_x, canvas_y,
 							  &day, &row,
 							  &event_num);
-	if (event_num != -1)
+	if (event_num != -1) {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return FALSE;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
+	}
 
 	if (day_view->selection_is_being_dragged) {
 		if (pos != E_CALENDAR_VIEW_POS_OUTSIDE) {
@@ -3702,7 +3787,7 @@ e_day_view_on_main_canvas_motion (GtkWidget *widget,
 		cursor = day_view->normal_cursor;
 
 		/* Check if the event is editable and client is not readonly while changing the cursor */
-		if (event && event->is_editable && e_cal_is_read_only (event->comp_data->client, &read_only, NULL) && !read_only) {
+		if (event && event->is_editable && is_comp_data_valid (event) && e_cal_is_read_only (event->comp_data->client, &read_only, NULL) && !read_only) {
 
 			switch (pos) {
 			case E_CALENDAR_VIEW_POS_LEFT_EDGE:
@@ -3893,10 +3978,14 @@ e_day_view_update_resize (EDayView *day_view,
 
 	day = day_view->resize_event_day;
 	event_num = day_view->resize_event_num;
+
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
-	if (event && (!event->is_editable || (e_cal_is_read_only (event->comp_data->client, &read_only, NULL) && read_only))) {
+	if (event && (!event->is_editable || !is_comp_data_valid (event) || (e_cal_is_read_only (event->comp_data->client, &read_only, NULL) && read_only))) {
 		return;
 	}
 
@@ -3941,9 +4030,16 @@ e_day_view_finish_long_event_resize (EDayView *day_view)
 	gint is_date;
 
 	event_num = day_view->resize_event_num;
+
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	client = event->comp_data->client;
 
 	/* We use a temporary copy of the comp since we don't want to
@@ -4052,9 +4148,16 @@ e_day_view_finish_resize (EDayView *day_view)
 
 	day = day_view->resize_event_day;
 	event_num = day_view->resize_event_num;
+
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	client = event->comp_data->client;
 
 	/* We use a temporary shallow copy of the ico since we don't want to
@@ -4202,7 +4305,8 @@ e_day_view_free_event_array (EDayView *day_view,
 		if (event->canvas_item)
 			gtk_object_destroy (GTK_OBJECT (event->canvas_item));
 
-		e_cal_model_free_component_data (event->comp_data);
+		if (is_comp_data_valid (event))
+			e_cal_model_free_component_data (event->comp_data);
 	}
 
 	g_array_set_size (array, 0);
@@ -4415,6 +4519,9 @@ e_day_view_reshape_long_event (EDayView *day_view,
 	PangoContext *pango_context;
 	PangoLayout *layout;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
@@ -4429,6 +4536,9 @@ e_day_view_reshape_long_event (EDayView *day_view,
 		return;
 	}
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* Take off the border and padding. */
 	item_x += E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD;
 	item_w -= (E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH + E_DAY_VIEW_LONG_EVENT_X_PAD) * 2;
@@ -4574,6 +4684,10 @@ e_day_view_reshape_day_events (EDayView *day_view,
 
 		e_day_view_reshape_day_event (day_view, day, event_num);
 		event = &g_array_index (day_view->events[day], EDayViewEvent, event_num);
+
+		if (!is_comp_data_valid (event))
+			continue;
+
 		current_comp_string = icalcomponent_as_ical_string_r (event->comp_data->icalcomp);
 		if (day_view->last_edited_comp_string == NULL) {
 			g_free (current_comp_string);
@@ -4598,6 +4712,9 @@ e_day_view_reshape_day_event (EDayView *day_view,
 	gint item_x, item_y, item_w, item_h;
 	gint num_icons, icons_offset;
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
@@ -4619,9 +4736,9 @@ e_day_view_reshape_day_event (EDayView *day_view,
 		   draw them on top of the resize rect. */
 		icons_offset = 0;
 		num_icons = 0;
-		if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_NONE
+		if (is_comp_data_valid (event) && (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_NONE
 		    || day_view->resize_event_day != day
-		    || day_view->resize_event_num != event_num) {
+		    || day_view->resize_event_num != event_num)) {
 			ECalComponent *comp;
 
 			comp = e_cal_component_new ();
@@ -5669,13 +5786,22 @@ e_day_view_start_editing_event (EDayView *day_view,
 		return;
 
 	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
 	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
 	}
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	if (!e_cal_is_read_only (event->comp_data->client, &read_only, NULL) || read_only)
 		return;
 
@@ -5747,10 +5873,20 @@ cancel_editing (EDayView *day_view)
 
 	g_return_if_fail (day != -1);
 
-	if (day == E_DAY_VIEW_LONG_EVENT)
+	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent, event_num);
-	else
+	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent, event_num);
+	}
+
+	if (!is_comp_data_valid (event))
+		return;
 
 	/* Reset the text to what was in the component */
 
@@ -5769,9 +5905,15 @@ tooltip_get_view_event (EDayView *day_view, gint day, gint event_num)
 	EDayViewEvent *pevent;
 
 	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return  NULL;
+
 		pevent = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
 	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return NULL;
+
 		pevent = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
 	}
@@ -5980,6 +6122,9 @@ e_day_view_event_move (ECalendarView *cal_view, ECalViewMoveDirection direction)
 	if ((day == -1) || (day == E_DAY_VIEW_LONG_EVENT))
 		return FALSE;
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return FALSE;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 	day_view->resize_event_day = day;
@@ -6056,8 +6201,16 @@ e_day_view_change_event_time (EDayView *day_view, time_t start_dt, time_t end_dt
 
 	day = day_view->editing_event_day;
 	event_num = day_view->editing_event_num;
+
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
 	client = event->comp_data->client;
 
 	/* We use a temporary shallow copy of the ico since we don't want to
@@ -6131,6 +6284,10 @@ e_day_view_change_event_end_time_up (EDayView *day_view)
 	event_num = day_view->editing_event_num;
 	if ((day == -1) || (day == E_DAY_VIEW_LONG_EVENT))
 		return;
+
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 	day_view->resize_event_day = day;
@@ -6161,6 +6318,10 @@ e_day_view_change_event_end_time_down (EDayView *day_view)
 	event_num = day_view->editing_event_num;
 	if ((day == -1) || (day == E_DAY_VIEW_LONG_EVENT))
 		return;
+
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 	day_view->resize_event_day = day;
@@ -6262,14 +6423,23 @@ e_day_view_on_editing_stopped (EDayView *day_view,
 		return;
 
 	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
 	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
 
 	}
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* Reset the edit fields. */
 	day_view->editing_event_day = -1;
 	day_view->editing_event_num = -1;
@@ -6606,6 +6776,9 @@ e_day_view_get_event_rows (EDayView *day_view,
 	g_return_val_if_fail (day < E_DAY_VIEW_LONG_EVENT, FALSE);
 	g_return_val_if_fail (event_num >= 0, FALSE);
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return FALSE;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 	start_row = event->start_minute / day_view->mins_per_row;
@@ -6630,6 +6803,9 @@ e_day_view_get_event_position (EDayView *day_view,
 	EDayViewEvent *event;
 	gint start_row, end_row, cols_in_row, start_col, num_columns;
 
+	if (!is_array_index_in_bounds (day_view->events[day], event_num))
+		return FALSE;
+
 	event = &g_array_index (day_view->events[day], EDayViewEvent,
 				event_num);
 
@@ -6684,6 +6860,9 @@ e_day_view_get_long_event_position	(EDayView	*day_view,
 {
 	EDayViewEvent *event;
 
+	if (!is_array_index_in_bounds (day_view->long_events, event_num))
+		return FALSE;
+
 	event = &g_array_index (day_view->long_events, EDayViewEvent,
 				event_num);
 
@@ -6951,6 +7130,9 @@ e_day_view_update_top_canvas_drag (EDayView *day_view,
 	num_days = 1;
 
 	if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, day_view->drag_event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					day_view->drag_event_num);
 		row = event->start_row_or_col + 1;
@@ -6967,6 +7149,9 @@ e_day_view_update_top_canvas_drag (EDayView *day_view,
 		day = MIN (day, day_view->days_shown - num_days);
 
 	} else if (day_view->drag_event_day != -1) {
+		if (!is_array_index_in_bounds (day_view->events[day_view->drag_event_day], day_view->drag_event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day_view->drag_event_day],
 					EDayViewEvent,
 					day_view->drag_event_num);
@@ -7014,7 +7199,7 @@ e_day_view_update_top_canvas_drag (EDayView *day_view,
 	      & GNOME_CANVAS_ITEM_VISIBLE)) {
 		const gchar *summary;
 
-		if (event) {
+		if (event && is_comp_data_valid (event)) {
 			summary = icalcomponent_get_summary (event->comp_data->icalcomp);
 			text = g_strdup (summary);
 		} else {
@@ -7107,9 +7292,15 @@ e_day_view_update_main_canvas_drag (EDayView *day_view,
 	num_rows = 1;
 
 	if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, day_view->drag_event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					day_view->drag_event_num);
 	} else if (day_view->drag_event_day != -1) {
+		if (!is_array_index_in_bounds (day_view->events[day_view->drag_event_day], day_view->drag_event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day_view->drag_event_day],
 					EDayViewEvent,
 					day_view->drag_event_num);
@@ -7173,7 +7364,7 @@ e_day_view_update_main_canvas_drag (EDayView *day_view,
 	if (!(day_view->drag_item->object.flags & GNOME_CANVAS_ITEM_VISIBLE)) {
 		const gchar *summary;
 
-		if (event) {
+		if (event && is_comp_data_valid (event)) {
 			summary = icalcomponent_get_summary (event->comp_data->icalcomp);
 			text = g_strdup (summary);
 		} else {
@@ -7237,12 +7428,19 @@ e_day_view_on_drag_begin (GtkWidget      *widget,
 	g_return_if_fail (day != -1);
 	g_return_if_fail (event_num != -1);
 
-	if (day == E_DAY_VIEW_LONG_EVENT)
+	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
-	else
+	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
+	}
 
 	/* Hide the text item, since it will be shown in the special drag
 	   items. */
@@ -7266,10 +7464,16 @@ e_day_view_on_drag_end (GtkWidget      *widget,
 		return;
 
 	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events, EDayViewEvent,
 					event_num);
 		gtk_widget_queue_draw (day_view->top_canvas);
 	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day], EDayViewEvent,
 					event_num);
 		gtk_widget_queue_draw (day_view->main_canvas);
@@ -7300,12 +7504,22 @@ e_day_view_on_drag_data_get (GtkWidget          *widget,
 	g_return_if_fail (day != -1);
 	g_return_if_fail (event_num != -1);
 
-	if (day == E_DAY_VIEW_LONG_EVENT)
+	if (day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events,
 					EDayViewEvent, event_num);
-	else
+	} else {
+		if (!is_array_index_in_bounds (day_view->events[day], event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day],
 					EDayViewEvent, event_num);
+	}
+
+	if (!is_comp_data_valid (event))
+		return;
 
 	if (info == TARGET_CALENDAR_EVENT || info == TARGET_VCALENDAR) {
 		/* we will pass an icalcalendar component for both types */
@@ -7383,8 +7597,15 @@ e_day_view_on_top_canvas_drag_data_received  (GtkWidget          *widget,
 			end_offset = 0;
 
 			if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) {
+				if (!is_array_index_in_bounds (day_view->long_events, day_view->drag_event_num))
+					return;
+
 				event = &g_array_index (day_view->long_events, EDayViewEvent,
 							day_view->drag_event_num);
+
+				if (!is_comp_data_valid (event))
+					return;
+
 				day -= day_view->drag_event_offset;
 				day = MAX (day, 0);
 
@@ -7400,9 +7621,15 @@ e_day_view_on_top_canvas_drag_data_received  (GtkWidget          *widget,
 				start_offset = event->start_minute;
 				end_offset = event->end_minute;
 			} else {
+				if (!is_array_index_in_bounds (day_view->events[day_view->drag_event_day], day_view->drag_event_num))
+					return;
+
 				event = &g_array_index (day_view->events[day_view->drag_event_day],
 							EDayViewEvent,
 							day_view->drag_event_num);
+
+				if (!is_comp_data_valid (event))
+					return;
 			}
 
 			client = event->comp_data->client;
@@ -7612,12 +7839,25 @@ e_day_view_on_main_canvas_drag_data_received  (GtkWidget          *widget,
 			end_offset = 0;
 
 			if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT) {
+				if (!is_array_index_in_bounds (day_view->long_events, day_view->drag_event_num))
+					return;
+
 				event = &g_array_index (day_view->long_events, EDayViewEvent,
 							day_view->drag_event_num);
+
+				if (!is_comp_data_valid (event))
+					return;
 			} else {
+				if (!is_array_index_in_bounds (day_view->events[day_view->drag_event_day], day_view->drag_event_num))
+					return;
+
 				event = &g_array_index (day_view->events[day_view->drag_event_day],
 							EDayViewEvent,
 							day_view->drag_event_num);
+
+				if (!is_comp_data_valid (event))
+					return;
+
 				row -= day_view->drag_event_offset;
 
 				/* Calculate time offset from start row. */
@@ -7869,10 +8109,16 @@ e_day_view_paste_text (ECalendarView *cal_view)
 		return;
 
 	if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT) {
+		if (!is_array_index_in_bounds (day_view->long_events, day_view->editing_event_num))
+			return;
+
 		event = &g_array_index (day_view->long_events,
 					EDayViewEvent,
 					day_view->editing_event_num);
 	} else {
+		if (!is_array_index_in_bounds (day_view->events[day_view->editing_event_day], day_view->editing_event_num))
+			return;
+
 		event = &g_array_index (day_view->events[day_view->editing_event_day],
 					EDayViewEvent,
 					day_view->editing_event_num);
diff --git a/calendar/gui/e-week-view-event-item.c b/calendar/gui/e-week-view-event-item.c
index ed939fe..5a098cf 100644
--- a/calendar/gui/e-week-view-event-item.c
+++ b/calendar/gui/e-week-view-event-item.c
@@ -283,11 +283,20 @@ e_week_view_event_item_draw (GnomeCanvasItem  *canvas_item,
 
 	g_return_if_fail (wveitem->event_num < week_view->events->len);
 
+	if (!is_array_index_in_bounds (week_view->events, wveitem->event_num))
+ 		return;
+	
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				wveitem->event_num);
 
+	if (!is_comp_data_valid (event))
+ 		return;
+		
 	g_return_if_fail (event->spans_index + wveitem->span_num < week_view->spans->len);
 
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + wveitem->span_num))
+ 		return;
+	
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + wveitem->span_num);
 
@@ -739,8 +748,14 @@ e_week_view_event_item_draw_icons (EWeekViewEventItem *wveitem,
 
 	week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent);
 
+	if (!is_array_index_in_bounds (week_view->events, wveitem->event_num))
+ 		return;
+	
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				wveitem->event_num);
+	if (!is_comp_data_valid (event))
+ 		return;
+	
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 
@@ -853,9 +868,15 @@ e_week_view_event_item_draw_triangle (EWeekViewEventItem *wveitem,
 
 	week_view = E_WEEK_VIEW (GTK_WIDGET (GNOME_CANVAS_ITEM (wveitem)->canvas)->parent);
 
+	if (!is_array_index_in_bounds (week_view->events, wveitem->event_num))
+ 		return;
+	
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				wveitem->event_num);
 
+	if (!is_comp_data_valid (event))
+ 		return;
+	
 	gc = week_view->main_gc;
 	cr = gdk_cairo_create (drawable);
 
@@ -961,8 +982,15 @@ e_week_view_event_item_button_press (EWeekViewEventItem *wveitem,
 	week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent);
 	g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);
 
+	if (!is_array_index_in_bounds (week_view->events, wveitem->event_num))
+ 		return FALSE;
+	
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				wveitem->event_num);
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + wveitem->span_num))
+ 		return FALSE;
+	
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + wveitem->span_num);
 
@@ -1060,14 +1088,25 @@ e_week_view_event_item_double_click (EWeekViewEventItem *wveitem,
 	week_view = E_WEEK_VIEW (GTK_WIDGET (item->canvas)->parent);
 	g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);
 
+	if (!is_array_index_in_bounds (week_view->events, wveitem->event_num))
+ 		return TRUE;
+	
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				wveitem->event_num);
 
+	if (!is_comp_data_valid (event))
+		return TRUE;
+		
 	if (week_view->editing_event_num >= 0) {
-		EWeekViewEvent *editing = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num);
+		EWeekViewEvent *editing;
+		
+		if (!is_array_index_in_bounds (week_view->events, week_view->editing_event_num))
+			return TRUE;
+		
+		 editing = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num);
 
 		/* do not call edit of the component, if double clicked on the component, which is not on the server */
-		if (editing && event && editing->comp_data == event->comp_data && (!event->comp_data || !is_icalcomp_on_the_server (event->comp_data->icalcomp, event->comp_data->client)))
+		if (editing && event && editing->comp_data == event->comp_data && is_comp_data_valid (editing) && (!event->comp_data || !is_icalcomp_on_the_server (event->comp_data->icalcomp, event->comp_data->client)))
 			return TRUE;
 	}
 
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 4d21eae..7cb2511 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -850,7 +850,7 @@ e_week_view_get_text_color (EWeekView *week_view, EWeekViewEvent *event, GtkWidg
 	green = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].green;
 	blue = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].blue;
 
-	if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), event->comp_data),
+	if (is_comp_data_valid (event) && gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)), event->comp_data),
 	     &bg_color)) {
                 GdkColormap *colormap;
 		colormap = gtk_widget_get_colormap (GTK_WIDGET (week_view));
@@ -1312,9 +1312,16 @@ e_week_view_focus (GtkWidget *widget, GtkDirectionType direction)
 			EWeekViewEventSpan *span;
 			gint current_day;
 
+			if (!is_array_index_in_bounds (week_view->events, new_event_num))
+				break;
+
 			event = &g_array_index (week_view->events,
 						EWeekViewEvent,
 						new_event_num);
+
+			if (!is_array_index_in_bounds (week_view->spans, event->spans_index + new_span_num))
+				break;
+
 			span = &g_array_index (week_view->spans,
 					       EWeekViewEventSpan,
 					       event->spans_index + new_span_num);
@@ -1344,9 +1351,15 @@ e_week_view_get_selected_events (ECalendarView *cal_view)
 	g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL);
 
 	if (week_view->editing_event_num != -1) {
+		if (!is_array_index_in_bounds (week_view->events, week_view->editing_event_num))
+			return NULL;
+
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					week_view->editing_event_num);
 	} else if (week_view->popup_event_num != -1) {
+		if (!is_array_index_in_bounds (week_view->events, week_view->popup_event_num))
+			return NULL;
+
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					week_view->popup_event_num);
 	}
@@ -1927,6 +1940,9 @@ set_text_as_bold (EWeekViewEvent *event, EWeekViewEventSpan *span)
 	gchar *address;
 	ECalComponentAttendee *at = NULL;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 	address = itip_get_comp_attendee (comp, event->comp_data->client);
@@ -1972,6 +1988,9 @@ e_week_view_foreach_event_with_uid (EWeekView *week_view,
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
 
+		if (!is_comp_data_valid (event))
+			continue;
+
 		u = icalcomponent_get_uid (event->comp_data->icalcomp);
 		if (u && !strcmp (uid, u)) {
 			if (!(*callback) (week_view, event_num, data))
@@ -1989,6 +2008,9 @@ e_week_view_remove_event_cb (EWeekView *week_view,
 	EWeekViewEventSpan *span;
 	gint span_num;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return TRUE;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
 	if (!event)
 		return TRUE;
@@ -2001,13 +2023,16 @@ e_week_view_remove_event_cb (EWeekView *week_view,
 	if (week_view->popup_event_num == event_num)
 		week_view->popup_event_num = -1;
 
-	e_cal_model_free_component_data (event->comp_data);
+	if (is_comp_data_valid (event))
+		e_cal_model_free_component_data (event->comp_data);
 	event->comp_data = NULL;
 
 	if (week_view->spans) {
 		/* We leave the span elements in the array, but set the canvas item
 		   pointers to NULL. */
 		for (span_num = 0; span_num < event->num_spans; span_num++) {
+			if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+					break;
 			span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 					       event->spans_index + span_num);
 
@@ -2100,6 +2125,9 @@ e_week_view_get_span_position	(EWeekView	*week_view,
 
 	g_return_val_if_fail (span_num < event->num_spans, FALSE);
 
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return FALSE;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + span_num);
 
@@ -2142,7 +2170,14 @@ ewv_pass_gdkevent_to_etext (EWeekView *week_view, GdkEvent *gevent)
 		EWeekViewEvent *event;
 		EWeekViewEventSpan *span;
 
+		if (!is_array_index_in_bounds (week_view->events, week_view->editing_event_num))
+			return FALSE;
+
 		event = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num);
+
+		if (!is_array_index_in_bounds (week_view->spans, event->spans_index + week_view->editing_span_num))
+			return FALSE;
+
 		span = &g_array_index (week_view->spans, EWeekViewEventSpan, event->spans_index + week_view->editing_span_num);
 
 		if (span->text_item && E_IS_TEXT (span->text_item)) {
@@ -2434,7 +2469,8 @@ e_week_view_free_events (EWeekView *week_view)
 	for (event_num = 0; event_num < week_view->events->len; event_num++) {
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
-		e_cal_model_free_component_data (event->comp_data);
+		if (is_comp_data_valid (event))
+			e_cal_model_free_component_data (event->comp_data);
 	}
 
 	g_array_set_size (week_view->events, 0);
@@ -2616,6 +2652,9 @@ e_week_view_reshape_events (EWeekView *week_view)
 	for (event_num = 0; event_num < week_view->events->len; event_num++) {
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
+		if (!is_comp_data_valid (event))
+			continue;
+
 		for (span_num = 0; span_num < event->num_spans; span_num++) {
 			gchar *current_comp_string;
 
@@ -2626,6 +2665,12 @@ e_week_view_reshape_events (EWeekView *week_view)
 			current_comp_string = icalcomponent_as_ical_string_r (event->comp_data->icalcomp);
 			if (strncmp (current_comp_string, week_view->last_edited_comp_string,50) == 0) {
 				EWeekViewEventSpan *span;
+
+				if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num)) {
+					g_free (current_comp_string);
+					continue;
+				}
+
 				span = &g_array_index (week_view->spans, EWeekViewEventSpan, event->spans_index + span_num);
 				e_canvas_item_grab_focus (span->text_item, TRUE);
 				g_free (week_view->last_edited_comp_string);
@@ -2674,6 +2719,9 @@ tooltip_get_view_event (EWeekView *week_view, gint day, gint event_num)
 {
 	EWeekViewEvent *pevent;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return NULL;
+
 	pevent = &g_array_index (week_view->events, EWeekViewEvent, event_num);
 
 	return pevent;
@@ -2772,7 +2820,17 @@ e_week_view_reshape_event_span (EWeekView *week_view,
 	PangoFontMetrics *font_metrics;
 	PangoLayout *layout;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + span_num);
 	comp = e_cal_component_new ();
@@ -3042,7 +3100,17 @@ e_week_view_start_editing_event (EWeekView *week_view,
 	    && span_num == week_view->editing_span_num)
 		return TRUE;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return FALSE;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
+
+	if (!is_comp_data_valid (event))
+		return FALSE;
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return FALSE;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + span_num);
 
@@ -3054,7 +3122,12 @@ e_week_view_start_editing_event (EWeekView *week_view,
 		return FALSE;
 
 	if (week_view->editing_event_num >= 0) {
-		EWeekViewEvent *editing = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num);
+		EWeekViewEvent *editing;
+
+		if (!is_array_index_in_bounds (week_view->events, week_view->editing_event_num))
+			return FALSE;
+
+		editing = &g_array_index (week_view->events, EWeekViewEvent, week_view->editing_event_num);
 
 		/* do not change to other part of same component - the event is spread into more days */
 		if (editing && event && editing->comp_data == event->comp_data)
@@ -3091,6 +3164,10 @@ e_week_view_start_editing_event (EWeekView *week_view,
 		}
 		g_return_val_if_fail (event_num >= 0, FALSE);
 	}
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return FALSE;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,  event->spans_index + span_num);
 
 	/* Try to move the cursor to the end of the text. */
@@ -3135,7 +3212,17 @@ cancel_editing (EWeekView *week_view)
 
 	g_return_if_fail (event_num != -1);
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan, event->spans_index + span_num);
 
 	/* Reset the text to what was in the component */
@@ -3191,9 +3278,15 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
 						       &event_num, &span_num))
 			return FALSE;
 
+		if (!is_array_index_in_bounds (week_view->events, event_num))
+			return FALSE;
+
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
 
+		if (!is_comp_data_valid (event))
+			return FALSE;
+
 		/* if we started to editing new item on the canvas, then do not open editing dialog until it's saved,
 		   because the save of the event recalculates event numbers and you can edit different one */
 		if (!is_icalcomp_on_the_server (event->comp_data->icalcomp, event->comp_data->client))
@@ -3220,6 +3313,9 @@ e_week_view_on_text_item_event (GnomeCanvasItem *item,
 				return FALSE;
 			}
 
+			if (!is_array_index_in_bounds (week_view->events, event_num))
+				return FALSE;
+
 			e = &g_array_index (week_view->events, EWeekViewEvent, event_num);
 
 			if (!GTK_WIDGET_HAS_FOCUS (week_view))
@@ -3357,8 +3453,14 @@ static gboolean e_week_view_event_move (ECalendarView *cal_view, ECalViewMoveDir
 	if (event_num == -1)
 		return FALSE;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+ 		return FALSE;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
 
+	if (!is_comp_data_valid (event))
+		return FALSE;
+	
 	start_dt = event->start;
 	end_dt = event->end;
 	start_time = icalcomponent_get_dtstart (event->comp_data->icalcomp);
@@ -3470,7 +3572,14 @@ e_week_view_change_event_time (EWeekView *week_view, time_t start_dt, time_t end
 	if (event_num == -1)
 		return;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
 	client = event->comp_data->client;
 
 	/* We use a temporary shallow copy of the ico since we don't want to
@@ -3577,7 +3686,17 @@ e_week_view_on_editing_stopped (EWeekView *week_view,
 	if (event_num == -1)
 		return;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
+
+	if (!is_comp_data_valid (event))
+		return;
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+		return;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + span_num);
 
@@ -3725,6 +3844,9 @@ e_week_view_find_event_from_item (EWeekView	  *week_view,
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
 		for (span_num = 0; span_num < event->num_spans; span_num++) {
+			if (!is_array_index_in_bounds (week_view->spans, event->spans_index + span_num))
+				continue;
+
 			span = &g_array_index (week_view->spans,
 					       EWeekViewEventSpan,
 					       event->spans_index + span_num);
@@ -3767,6 +3889,9 @@ e_week_view_find_event_from_uid (EWeekView	  *week_view,
 		event = &g_array_index (week_view->events, EWeekViewEvent,
 					event_num);
 
+		if (!is_comp_data_valid (event))
+			continue;
+
 		if (event->comp_data->client != client)
 			continue;
 
@@ -3798,10 +3923,16 @@ e_week_view_is_one_day_event	(EWeekView	*week_view,
 	EWeekViewEvent *event;
 	EWeekViewEventSpan *span;
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return FALSE;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent, event_num);
 	if (event->num_spans != 1)
 		return FALSE;
 
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index))
+		return FALSE;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index);
 
@@ -4109,8 +4240,15 @@ e_week_view_add_new_event_in_selected_range (EWeekView *week_view, const gchar *
 		return FALSE;
 	}
 
+	if (!is_array_index_in_bounds (week_view->events, event_num))
+		return FALSE;
+
 	wvevent = &g_array_index (week_view->events, EWeekViewEvent,
 				  event_num);
+
+	if (!is_array_index_in_bounds (week_view->spans, wvevent->spans_index + 0))
+		return FALSE;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       wvevent->spans_index + 0);
 
@@ -4497,8 +4635,15 @@ e_week_view_paste_text (ECalendarView *cal_view)
 	    !e_week_view_add_new_event_in_selected_range (week_view, NULL))
 		return;
 
+	if (!is_array_index_in_bounds (week_view->events, week_view->editing_event_num))
+		return;
+
 	event = &g_array_index (week_view->events, EWeekViewEvent,
 				week_view->editing_event_num);
+
+	if (!is_array_index_in_bounds (week_view->spans, event->spans_index + week_view->editing_span_num))
+		return;
+
 	span = &g_array_index (week_view->spans, EWeekViewEventSpan,
 			       event->spans_index + week_view->editing_span_num);
 
diff --git a/calendar/gui/print.c b/calendar/gui/print.c
index eb18b48..b30624e 100644
--- a/calendar/gui/print.c
+++ b/calendar/gui/print.c
@@ -1090,6 +1090,9 @@ print_day_long_event (GtkPrintContext *context, PangoFontDescription *font,
 	struct tm date_tm;
 	double red, green, blue;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	/* If the event starts before the first day being printed, draw a
 	   triangle. (Note that I am assuming we are just showing 1 day at
 	   the moment.) */
@@ -1169,6 +1172,9 @@ print_day_event (GtkPrintContext *context, PangoFontDescription *font,
 	struct tm date_tm;
 	double red, green, blue;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	if ((event->start_minute >= pdi->end_minute_offset)
 	    || (event->end_minute <= pdi->start_minute_offset))
 		return;
@@ -1538,6 +1544,9 @@ print_week_event (GtkPrintContext *context, PangoFontDescription *font,
 	double red, green, blue;
 	GdkPixbuf *pixbuf = NULL;
 
+	if (!is_comp_data_valid (event))
+		return;
+
 	text = get_summary_with_location (event->comp_data->icalcomp);
 
 	for (span_num = 0; span_num < event->num_spans; span_num++) {
diff --git a/plugins/groupwise-features/process-meeting.c b/plugins/groupwise-features/process-meeting.c
index 299b19e..45cd562 100644
--- a/plugins/groupwise-features/process-meeting.c
+++ b/plugins/groupwise-features/process-meeting.c
@@ -199,13 +199,19 @@ process_meeting (ECalendarView *cal_view, icalparameter_partstat status)
 	selected = e_calendar_view_get_selected_events (cal_view);
 	if (selected) {
 		ECalendarViewEvent *event = (ECalendarViewEvent *) selected->data;
-		ECalComponent *comp = e_cal_component_new ();
-		ReceiveData *r_data = g_new0 (ReceiveData, 1);
+		ECalComponent *comp;
+		ReceiveData *r_data;
 		gboolean recurring = FALSE;
 		GThread *thread = NULL;
 		GError *error = NULL;
 		gchar *address = NULL;
 
+		if (!is_comp_data_valid (event))
+			return;
+
+		comp = e_cal_component_new ();
+		r_data = g_new0 (ReceiveData, 1);
+
 		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 		address = itip_get_comp_attendee (comp, event->comp_data->client);
 
@@ -483,7 +489,7 @@ on_resend_meeting (EPopup *ep, EPopupItem *pitem, gpointer data)
 	selected = e_calendar_view_get_selected_events (cal_view);
 	if (selected) {
 		ECalendarViewEvent *event = (ECalendarViewEvent *) selected->data;
-		ECalComponent *comp = e_cal_component_new ();
+		ECalComponent *comp;
 		ECalComponent *new_comp = NULL;
 		gboolean recurring = FALSE;
 		CalObjModType mod = CALOBJ_MOD_THIS;
@@ -493,6 +499,10 @@ on_resend_meeting (EPopup *ep, EPopupItem *pitem, gpointer data)
 		/* inserting the boolean to share the code between resend and retract */
 		gboolean resend = TRUE;
 
+		if (!is_comp_data_valid (event))
+			return;
+
+		comp = e_cal_component_new ();
 		e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp));
 		if (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp))
 			recurring = TRUE;
