[FFmpeg-devel] [PATCH] Variable used uninitialized

Ray Simard rhs.ffmpeg at sylvan-glade.com
Sat Jan 21 03:19:46 CET 2012


In this part of deshaking filter vf_deshake.c, dynamically-allocated
array angles collects information when certain conditions are met while
scanning an image for motion.

   pos = 0;
   for (y = deshake->ry; y < height - deshake->ry - ...
        for (x = deshake->rx; x < width - deshake->rx -  ...
    ...
                    if (x > deshake->rx && y > deshake->ry)
                        angles[pos++] = block_angle(x, y, 0, 0, &mv);

                    center_x += mv.x;
                    center_y += mv.y;
                }
            }
        }
    }

    pos = FFMAX(1, pos);

    center_x /= pos;
    center_y /= pos;

    t->angle = clean_mean(angles, pos);
    if (t->angle < 0.001)
        t->angle = 0;

When the scan is done, function clean_mean makes a few adjustments and
returns the mean of the values in the array.

Sometimes the scan finds nothing that qualifies for addition to
the array and pos is zero after the loops.  The code above 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.
I haven't run it through FATE yet.

Ray Simard
rhs.ffmpeg at sylvan-glade.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vf_deshake-variable-used-uninitialized.patch
Type: text/x-patch
Size: 805 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120120/f3b8fd76/attachment.bin>


More information about the ffmpeg-devel mailing list