diff --git a/ext/ttml/gstttmlrender.c b/ext/ttml/gstttmlrender.c index b6a63b5bf5..6c1689454a 100644 --- a/ext/ttml/gstttmlrender.c +++ b/ext/ttml/gstttmlrender.c @@ -1841,7 +1841,9 @@ gst_ttml_render_split_block (UnifiedBlock * block, GPtrArray * char_ranges) gint i; for (i = 0; i < char_ranges->len; ++i) { - gint index, first_offset, last_offset; + gint index; + gint first_offset = 0; + gint last_offset = 0; CharRange *range = g_ptr_array_index (char_ranges, i); UnifiedBlock *clone = gst_ttml_render_unified_block_copy (block); UnifiedElement *ue; @@ -1855,6 +1857,12 @@ gst_ttml_render_split_block (UnifiedBlock * block, GPtrArray * char_ranges) GST_CAT_LOG (ttmlrender_debug, "Last char in range is in element %d", index); + if (index < 0) { + GST_CAT_WARNING (ttmlrender_debug, "Range end not found in block text."); + gst_ttml_render_unified_block_free (clone); + continue; + } + /* Remove elements that are after the one that contains the range end. */ GST_CAT_LOG (ttmlrender_debug, "There are %d elements in cloned block.", gst_ttml_render_unified_block_element_count (clone)); @@ -1869,6 +1877,13 @@ gst_ttml_render_split_block (UnifiedBlock * block, GPtrArray * char_ranges) GST_CAT_LOG (ttmlrender_debug, "First char in range is in element %d", index); + if (index < 0) { + GST_CAT_WARNING (ttmlrender_debug, + "Range start not found in block text."); + gst_ttml_render_unified_block_free (clone); + continue; + } + /* Remove elements that are before the one that contains the range start. */ while (index > 0) { GST_CAT_LOG (ttmlrender_debug, "Removing first element in cloned block");