comparison bitstream.c @ 11232:7f75cd2bf32e libavcodec

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.
author mru
date Sun, 21 Feb 2010 15:11:57 +0000
parents f2a8cba717b0
children 2d49996fe7d1
comparison
equal deleted inserted replaced
11231:0fc1cdd984b7 11232:7f75cd2bf32e
156 #if defined(DEBUG_VLC) && 0 156 #if defined(DEBUG_VLC) && 0
157 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); 157 av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
158 #endif 158 #endif
159 /* if code matches the prefix, it is in the table */ 159 /* if code matches the prefix, it is in the table */
160 n -= n_prefix; 160 n -= n_prefix;
161 if (n > 0) {
161 if(flags & INIT_VLC_LE) 162 if(flags & INIT_VLC_LE)
162 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1); 163 code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
163 else 164 else
164 code_prefix2= code >> n; 165 code_prefix2= code >> n;
165 if (n > 0 && code_prefix2 == code_prefix) { 166 if (code_prefix2 == code_prefix) {
166 if (n <= table_nb_bits) { 167 if (n <= table_nb_bits) {
167 /* no need to add another table */ 168 /* no need to add another table */
168 j = (code << (table_nb_bits - n)) & (table_size - 1); 169 j = (code << (table_nb_bits - n)) & (table_size - 1);
169 nb = 1 << (table_nb_bits - n); 170 nb = 1 << (table_nb_bits - n);
170 for(k=0;k<nb;k++) { 171 for(k=0;k<nb;k++) {
193 n1 = -table[j][1]; //bits 194 n1 = -table[j][1]; //bits
194 if (n > n1) 195 if (n > n1)
195 n1 = n; 196 n1 = n;
196 table[j][1] = -n1; //bits 197 table[j][1] = -n1; //bits
197 } 198 }
199 }
198 } 200 }
199 } 201 }
200 202
201 /* second pass : fill auxillary tables recursively */ 203 /* second pass : fill auxillary tables recursively */
202 for(i=0;i<table_size;i++) { 204 for(i=0;i<table_size;i++) {