ttmlrender: Fix potential problem identified by clang

Clang's static analyser found potential code paths in which variables
were being used in comparisons when uninitialised. Fix by properly
handling out-of-range value returned by gst_ttml_get_element_index.
This commit is contained in:
Chris Bass 2017-04-19 16:06:52 +01:00 committed by Sebastian Dröge
parent 98ce1e11bc
commit 129bee3d02

View file

@ -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");