Skip to content

Commit 9ec3993

Browse files
Ray Simardmichaelni
authored andcommitted
deshake: variable used uninitialized
Sometimes the scan finds nothing that qualifies for addition to the array and pos is zero after the loops. The code forces pos to 1 and the array is then processed as if it had one valid element in it, producing some amusing but not very useful results. I don't see the rationale for this. If pos is zero coming out of the loops, the only appropriate thing to do is set t->angle to zero. The attached patch does that. It's worked properly in several tests so far. Signed-off-by: Michael Niedermayer <[email protected]>
1 parent bdd739e commit 9ec3993

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

libavfilter/vf_deshake.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,15 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
292292
}
293293
}
294294

295-
pos = FFMAX(1, pos);
296-
297-
center_x /= pos;
298-
center_y /= pos;
299-
300-
t->angle = clean_mean(angles, pos);
301-
if (t->angle < 0.001)
302-
t->angle = 0;
295+
if (pos) {
296+
center_x /= pos;
297+
center_y /= pos;
298+
t->angle = clean_mean(angles, pos);
299+
if (t->angle < 0.001)
300+
t->angle = 0;
301+
} else {
302+
t->angle = 0;
303+
}
303304

304305
// Find the most common motion vector in the frame and use it as the gmv
305306
for (y = deshake->ry * 2; y >= 0; y--) {

0 commit comments

Comments
 (0)