[FFmpeg-cvslog] r21939 - trunk/libavcodec/bitstream.c

mru subversion
Sun Feb 21 16:11:57 CET 2010


Author: mru
Date: Sun Feb 21 16:11:57 2010
New Revision: 21939

Log:
Avoid negative shifts in build_table()

A shift by a negative amount has undefined behaviour.  Even though
the result of this shift is never used, the shift itself could
cause an exception of some kind.

Modified:
   trunk/libavcodec/bitstream.c

Modified: trunk/libavcodec/bitstream.c
==============================================================================
--- trunk/libavcodec/bitstream.c	Sun Feb 21 15:41:39 2010	(r21938)
+++ trunk/libavcodec/bitstream.c	Sun Feb 21 16:11:57 2010	(r21939)
@@ -158,11 +158,12 @@ static int build_table(VLC *vlc, int tab
 #endif
         /* if code matches the prefix, it is in the table */
         n -= n_prefix;
+        if (n > 0) {
         if(flags & INIT_VLC_LE)
             code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
         else
             code_prefix2= code >> n;
-        if (n > 0 && code_prefix2 == code_prefix) {
+        if (code_prefix2 == code_prefix) {
             if (n <= table_nb_bits) {
                 /* no need to add another table */
                 j = (code << (table_nb_bits - n)) & (table_size - 1);
@@ -196,6 +197,7 @@ static int build_table(VLC *vlc, int tab
                 table[j][1] = -n1; //bits
             }
         }
+        }
     }
 
     /* second pass : fill auxillary tables recursively */



More information about the ffmpeg-cvslog mailing list