summaryrefslogtreecommitdiff
path: root/libavcodec/bitstream.c
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-02-21 15:11:57 +0000
committerMåns Rullgård <mans@mansr.com>2010-02-21 15:11:57 +0000
commit4c4e746566a98340e229831624f74a5636b62b65 (patch)
tree951f8942a79116ac3e7c241ba6b6e469c4cc8236 /libavcodec/bitstream.c
parent044a950d8230c881c7e6833f9999498784f3fc76 (diff)
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. Originally committed as revision 21939 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/bitstream.c')
-rw-r--r--libavcodec/bitstream.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 9002830cec..7549e7d8bb 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -158,11 +158,12 @@ static int build_table(VLC *vlc, int table_nb_bits,
#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 table_nb_bits,
table[j][1] = -n1; //bits
}
}
+ }
}
/* second pass : fill auxillary tables recursively */