summaryrefslogtreecommitdiff
path: root/libavcodec/ljpegenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-03-25 10:27:31 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-03-30 12:36:32 +0200
commit67f6e7ed6ddac43139984b6956f45bb5c1861546 (patch)
treea931d71df1442c32203715d2e6fa82a3fab6a4af /libavcodec/ljpegenc.c
parent11ff9cb5e976e87ec345e6f4856f62b86d6cb0b3 (diff)
avcodec: Remove cumbersome way of checking for amount of bytes left
Several encoders used code like the following to check for the amount of bytes left in a PutBitContext: pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) Besides the fact that using the pointers directly might pose a maintainence burden in the future this also leads to suboptimal code: The above code reads all three pointers (buf, buf_ptr and buf_end), but touching buf is unnecessary and switching to put_bytes_left() automatically fixes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/ljpegenc.c')
-rw-r--r--libavcodec/ljpegenc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index 3c68c08a3c..056b80b4b5 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -86,7 +86,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
const int modified_predictor = y ? s->pred : 1;
uint8_t *ptr = frame->data[0] + (linesize * y);
- if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < width * 4 * 4) {
+ if (put_bytes_left(pb, 0) < width * 4 * 4) {
av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
@@ -211,7 +211,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
for (mb_y = 0; mb_y < mb_height; mb_y++) {
- if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) <
+ if (put_bytes_left(pb, 0) <
mb_width * 4 * 3 * s->hsample[0] * s->vsample[0]) {
av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;