From f8344bc39580c0e1780ddd380b8b4e582584f1c3 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Wed, 20 Jun 2012 10:21:03 +0100 Subject: [PATCH] Add protection around use of broadcast->episode-> as the episode is not always set (currenly opentv has limitations that cause this to happen). --- src/dvr/dvr_db.c | 14 ++++++++------ src/htsp.c | 20 +++++++++++--------- src/webui/simpleui.c | 14 ++++++++------ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index 552b132a..24bba451 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -182,7 +182,7 @@ dvr_make_title(char *output, size_t outlen, dvr_entry_t *de) } if(cfg->dvr_flags & DVR_EPISODE_IN_TITLE) { - if(de->de_bcast) + if(de->de_bcast && de->de_bcast->episode) epg_episode_number_format(de->de_bcast->episode, output + strlen(output), outlen - strlen(output), @@ -354,7 +354,7 @@ dvr_entry_create_by_event(const char *config_name, const char *creator, dvr_autorec_entry_t *dae, dvr_prio_t pri) { - if(!e->channel || !e->episode->title) + if(!e->channel || !e->episode || !e->episode->title) return NULL; return _dvr_entry_create(config_name, e, @@ -635,7 +635,8 @@ static dvr_entry_t *_dvr_entry_update int start, stop; if (e) { - title = e->episode->title; + if (e->episode) + title = e->episode->title; start = e->start; stop = e->stop; } else { @@ -661,7 +662,8 @@ static dvr_entry_t *_dvr_entry_update } if (e) { - if (e->episode->genre_cnt && e->episode->genre_cnt != de->de_content_type) { + if (e->episode && + e->episode->genre_cnt && e->episode->genre_cnt != de->de_content_type) { de->de_content_type = e->episode->genre[0]; save = 1; } @@ -710,7 +712,7 @@ dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e) ude = dvr_entry_find_by_event_fuzzy(new_e); if (ude == NULL && de->de_sched_state == DVR_SCHEDULED) dvr_entry_cancel(de); - else if(new_e->episode->title != NULL) + else if(new_e->episode && new_e->episode->title) _dvr_entry_update(de, new_e, NULL, 0, 0); } } @@ -818,7 +820,7 @@ dvr_entry_find_by_event_fuzzy(epg_broadcast_t *e) { dvr_entry_t *de; - if (e->episode->title == NULL) + if (!e->episode || !e->episode->title) return NULL; LIST_FOREACH(de, &e->channel->ch_dvrs, de_channel_link) diff --git a/src/htsp.c b/src/htsp.c index d8e806fe..f8d35486 100644 --- a/src/htsp.c +++ b/src/htsp.c @@ -761,16 +761,18 @@ htsp_build_event(epg_broadcast_t *e) htsmsg_add_u32(out, "channelId", e->channel->ch_id); htsmsg_add_u32(out, "start", e->start); htsmsg_add_u32(out, "stop", e->stop); - if(e->episode->title != NULL) - htsmsg_add_str(out, "title", e->episode->title); - if(e->episode->description != NULL) - htsmsg_add_str(out, "description", e->episode->description); - else if(e->episode->summary != NULL) - htsmsg_add_str(out, "description", e->episode->summary); + if (e->episode) { + if(e->episode->title != NULL) + htsmsg_add_str(out, "title", e->episode->title); + if(e->episode->description != NULL) + htsmsg_add_str(out, "description", e->episode->description); + else if(e->episode->summary != NULL) + htsmsg_add_str(out, "description", e->episode->summary); - // TODO: only supports one entry! - if(e->episode->genre_cnt) - htsmsg_add_u32(out, "contentType", e->episode->genre[0]); + // TODO: only supports one entry! + if(e->episode->genre_cnt) + htsmsg_add_u32(out, "contentType", e->episode->genre[0]); + } if((de = dvr_entry_find_by_event(e)) != NULL) { htsmsg_add_u32(out, "dvrId", de->de_id); diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index 58f2fa61..1dfaee00 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -128,7 +128,7 @@ page_simple(http_connection_t *hc, "%02d:%02d-%02d:%02d %s%s%s
", e->id, a.tm_hour, a.tm_min, b.tm_hour, b.tm_min, - e->episode->title, + e->episode ? e->episode->title : "", rstatus ? " " : "", rstatus ?: ""); } } @@ -228,7 +228,7 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque) a.tm_hour, a.tm_min, b.tm_hour, b.tm_min); htsbuf_qprintf(hq, "
\"%s\": \"%s\"

", - e->channel->ch_name, e->episode->title); + e->channel->ch_name, e->episode ? e->episode->title : ""); dvr_status = de != NULL ? de->de_sched_state : DVR_NOSTATE; @@ -260,10 +260,12 @@ page_einfo(http_connection_t *hc, const char *remain, void *opaque) } htsbuf_qprintf(hq, ""); - if ( e->episode->description ) - htsbuf_qprintf(hq, "%s", e->episode->description); - else if ( e->episode->summary ) - htsbuf_qprintf(hq, "%s", e->episode->summary); + if (e->episode) { + if ( e->episode->description ) + htsbuf_qprintf(hq, "%s", e->episode->description); + else if ( e->episode->summary ) + htsbuf_qprintf(hq, "%s", e->episode->summary); + } pthread_mutex_unlock(&global_lock);