aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2016-01-01 02:41:06 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2016-01-15 17:39:04 +0100
commit1363d0759df3c6016bcbc30db016e3706ad5e6a7 (patch)
treea409bb6dae4a8cf9572241659e09573563149025 /libavcodec
parentf48392197d365f2a3a62e7ee8786fa4e9a41f3e9 (diff)
downloadffmpeg-1363d0759df3c6016bcbc30db016e3706ad5e6a7.tar.gz
avcodec/put_bits: Always check buffer end before writing
This causes a overall slowdown of 0.1 % (tested with mpeg4 single thread encoding of matrixbench at QP=3) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit cccb0ffccc3723acc7aab3a859b24743596dd9c0) Conflicts: libavcodec/put_bits.h
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/put_bits.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 08f6826ee3..ca4f08668d 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -164,9 +164,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
#ifdef BITSTREAM_WRITER_LE
bit_buf |= value << (32 - bit_left);
if (n >= bit_left) {
- av_assert2(s->buf_ptr+3<s->buf_end);
- AV_WL32(s->buf_ptr, bit_buf);
- s->buf_ptr += 4;
+ if (3 < s->buf_end - s->buf_ptr) {
+ AV_WL32(s->buf_ptr, bit_buf);
+ s->buf_ptr += 4;
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
+ av_assert2(0);
+ }
bit_buf = (bit_left == 32) ? 0 : value >> bit_left;
bit_left += 32;
}
@@ -178,9 +182,13 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value)
} else {
bit_buf <<= bit_left;
bit_buf |= value >> (n - bit_left);
- av_assert2(s->buf_ptr+3<s->buf_end);
- AV_WB32(s->buf_ptr, bit_buf);
- s->buf_ptr += 4;
+ if (3 < s->buf_end - s->buf_ptr) {
+ AV_WB32(s->buf_ptr, bit_buf);
+ s->buf_ptr += 4;
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too small\n");
+ av_assert2(0);
+ }
bit_left += 32 - n;
bit_buf = value;
}