diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c
index e34b95b0daf3f675bac82aa72f652ac03d39ff6f..7964014532ee1e4499f5094bc3faa68425e8d80f 100644
--- a/libavcodec/x86/dsputil_mmx.c
+++ b/libavcodec/x86/dsputil_mmx.c
@@ -860,7 +860,7 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w,
     }
 
     if (sides&EDGE_BOTTOM) {
-        for(i = 0; i < w; i += 4) {
+        for(i = 0; i < h; i += 4) {
             ptr= last_line + (i + 1) * wrap - w;
             __asm__ volatile(
                     "1:                             \n\t"