// Populate a list with candidate reference vectors from the
// spatial neighbours.
- for (i = 2; i < MVREF_NEIGHBOURS; ++i) {
+ for (i = 2; (i < MVREF_NEIGHBOURS) && (index < (MAX_MV_REFS - 2)); ++i) {
if (((mv_ref_search[i][0] << 7) >= xd->mb_to_left_edge) &&
((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
}
}
+ // Make sure we are able to add 0,0
+ if (index > (MAX_MV_REFS - 1)) {
+ index = (MAX_MV_REFS - 1);
+ }
+
// 0,0 is always a valid reference.
for (i = 0; i < index; ++i)
if (candidate_mvs[i].as_int == 0)