]> git.sesse.net Git - vlc/commitdiff
libass: avoid negative index in array
authorJean-Baptiste Kempf <jb@videolan.org>
Fri, 14 Nov 2014 22:50:52 +0000 (23:50 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 14 Nov 2014 22:50:52 +0000 (23:50 +0100)
modules/codec/libass.c

index 9ea4f382f7d622e945f2e61dccb0f03f26c2faf0..f6f14a63f76d8a152a8cad494f142a5b9d670134 100644 (file)
@@ -627,11 +627,14 @@ static int BuildRegions( rectangle_t *p_region, int i_max_region, ASS_Image *p_i
 #ifdef DEBUG_REGION
             msg_Err( p_spu, "Merging %d and %d", i_best_i, i_best_j );
 #endif
-            r_add( &region[i_best_i], &region[i_best_j] );
+            if( i_best_j >= 0 && i_best_i >= 0 )
+            {
+                r_add( &region[i_best_i], &region[i_best_j] );
 
-            if( i_best_j+1 < i_region )
-                memmove( &region[i_best_j], &region[i_best_j+1], sizeof(*region) * ( i_region - (i_best_j+1)  ) );
-            i_region--;
+                if( i_best_j+1 < i_region )
+                    memmove( &region[i_best_j], &region[i_best_j+1], sizeof(*region) * ( i_region - (i_best_j+1)  ) );
+                i_region--;
+            }
         }
     }