mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/movtextenc: Reset AVBPrint at the beginning, not end of encoding
This avoids abusing a variable called length for the return value and ensures that the AVBPrint is always reset before using it; previously this has been forgotten in some error paths. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
bb89a2f64f
commit
0b934f8f17
|
@ -646,6 +646,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
|
||||||
s->text_pos = 0;
|
s->text_pos = 0;
|
||||||
s->count = 0;
|
s->count = 0;
|
||||||
s->box_flags = 0;
|
s->box_flags = 0;
|
||||||
|
av_bprint_clear(&s->buffer);
|
||||||
for (i = 0; i < sub->num_rects; i++) {
|
for (i = 0; i < sub->num_rects; i++) {
|
||||||
const char *ass = sub->rects[i]->ass;
|
const char *ass = sub->rects[i]->ass;
|
||||||
|
|
||||||
|
@ -669,27 +670,20 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
|
||||||
AV_WB16(buf, s->byte_count);
|
AV_WB16(buf, s->byte_count);
|
||||||
buf += 2;
|
buf += 2;
|
||||||
|
|
||||||
if (!av_bprint_is_complete(&s->buffer)) {
|
if (!av_bprint_is_complete(&s->buffer))
|
||||||
length = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!s->buffer.len) {
|
if (!s->buffer.len)
|
||||||
length = 0;
|
return 0;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->buffer.len > bufsize - 3) {
|
if (s->buffer.len > bufsize - 3) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
|
av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
|
||||||
length = AVERROR_BUFFER_TOO_SMALL;
|
return AVERROR_BUFFER_TOO_SMALL;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf, s->buffer.str, s->buffer.len);
|
memcpy(buf, s->buffer.str, s->buffer.len);
|
||||||
length = s->buffer.len + 2;
|
length = s->buffer.len + 2;
|
||||||
|
|
||||||
exit:
|
|
||||||
av_bprint_clear(&s->buffer);
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue