[FFmpeg-cvslog] h264: fix invalid shifts in init_cavlc_level_tab()

Mans Rullgard git at videolan.org
Mon Mar 19 05:30:21 CET 2012


ffmpeg | branch: release/0.8 | Mans Rullgard <mans at mansr.com> | Tue Oct 11 12:58:31 2011 +0100| [ccb3b71b424680dd4cd1d99002befeed6ac95d00] | committer: Reinhard Tartler

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 at mansr.com>
(cherry picked from commit 8babfc033ecb6332155c1f8879e54dee41d16952)

Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ccb3b71b424680dd4cd1d99002befeed6ac95d00
---

 libavcodec/h264_cavlc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index 497166b..2661ab2 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -238,17 +238,18 @@ static inline int pred_non_zero_count(H264Context *h, int n){
 }
 
 static av_cold void init_cavlc_level_tab(void){
-    int suffix_length, mask;
+    int suffix_length;
     unsigned int i;
 
     for(suffix_length=0; suffix_length<7; suffix_length++){
         for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
             int prefix= LEVEL_TAB_BITS - av_log2(2*i);
-            int level_code= (prefix<<suffix_length) + (i>>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<<suffix_length);
 
-            mask= -(level_code&1);
-            level_code= (((2+level_code)>>1) ^ mask) - mask;
             if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
+                int level_code = (prefix << suffix_length) +
+                    (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length);
+                int mask = -(level_code&1);
+                level_code = (((2 + level_code) >> 1) ^ mask) - mask;
                 cavlc_level_tab[suffix_length][i][0]= level_code;
                 cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
             }else if(prefix + 1 <= LEVEL_TAB_BITS){



More information about the ffmpeg-cvslog mailing list