]> git.sesse.net Git - ffmpeg/commitdiff
imgconvert: avoid undefined left shift in avcodec_find_best_pix_fmt
authorJanne Grunau <janne-libav@jannau.net>
Mon, 2 Jul 2012 08:46:39 +0000 (10:46 +0200)
committerJanne Grunau <janne-libav@jannau.net>
Fri, 13 Jul 2012 15:29:27 +0000 (17:29 +0200)
CC: libav-stable@libav.org
libavcodec/imgconvert.c

index 90c9b7b255cf79ab91980659acbbc2d4164fb179..7a6102e08bd067b3e90c58e1516dda52cb820ba2 100644 (file)
@@ -599,7 +599,8 @@ static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask,
     /* find exact color match with smallest size */
     dst_pix_fmt = PIX_FMT_NONE;
     min_dist = 0x7fffffff;
-    for(i = 0;i < PIX_FMT_NB; i++) {
+    /* test only the first 64 pixel formats to avoid undefined behaviour */
+    for (i = 0; i < 64; i++) {
         if (pix_fmt_mask & (1ULL << i)) {
             loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
             if (loss == 0) {