Browse code

h264: fix invalid shifts in init_cavlc_level_tab()

The level_code expression includes a shift which is invalid in
those cases where the value is not used. Moving the calculation
to the branch where the result is used avoids these.

Signed-off-by: Mans Rullgard <mans@mansr.com>

Mans Rullgard authored on 2011/10/11 20:58:31
Showing 1 changed files
... ...
@@ -238,17 +238,18 @@ static inline int pred_non_zero_count(H264Context *h, int n){
238 238
 }
239 239
 
240 240
 static av_cold void init_cavlc_level_tab(void){
241
-    int suffix_length, mask;
241
+    int suffix_length;
242 242
     unsigned int i;
243 243
 
244 244
     for(suffix_length=0; suffix_length<7; suffix_length++){
245 245
         for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
246 246
             int prefix= LEVEL_TAB_BITS - av_log2(2*i);
247
-            int level_code= (prefix<<suffix_length) + (i>>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<<suffix_length);
248 247
 
249
-            mask= -(level_code&1);
250
-            level_code= (((2+level_code)>>1) ^ mask) - mask;
251 248
             if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
249
+                int level_code = (prefix << suffix_length) +
250
+                    (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
251
+                int mask = -(level_code&1);
252
+                level_code = (((2 + level_code) >> 1) ^ mask) - mask;
252 253
                 cavlc_level_tab[suffix_length][i][0]= level_code;
253 254
                 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
254 255
             }else if(prefix + 1 <= LEVEL_TAB_BITS){