avformat: Forward errors where possible

It is not uncommon to find code where the caller thinks to know better
what the return value should be than the callee. E.g. something like
"if (av_new_packet(pkt, size) < 0) return AVERROR(ENOMEM);". This commit
changes several instances of this to instead forward the actual error.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Andreas Rheinhardt
2019-12-10 22:59:53 +01:00
committed by Michael Niedermayer
parent cb88cdf773
commit c1e439d7e9
71 changed files with 310 additions and 275 deletions

View File

@@ -63,7 +63,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
int flags)
{
int ident, fragmented, tdt, num_pkts, pkt_len;
int ident, fragmented, tdt, num_pkts, pkt_len, ret;
if (!buf) {
if (!data->split_buf || data->split_pos + 2 > data->split_buf_len ||
@@ -77,9 +77,9 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
av_log(ctx, AV_LOG_ERROR, "Not enough data to return\n");
return AVERROR_INVALIDDATA;
}
if (av_new_packet(pkt, pkt_len)) {
if ((ret = av_new_packet(pkt, pkt_len)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
return AVERROR(ENOMEM);
return ret;
}
pkt->stream_index = st->index;
memcpy(pkt->data, data->split_buf + data->split_pos, pkt_len);
@@ -123,9 +123,9 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
len -= 6;
if (fragmented == 0) {
if (av_new_packet(pkt, pkt_len)) {
if ((ret = av_new_packet(pkt, pkt_len)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
return AVERROR(ENOMEM);
return ret;
}
pkt->stream_index = st->index;
memcpy(pkt->data, buf, pkt_len);
@@ -228,6 +228,7 @@ parse_packed_headers(AVFormatContext *s,
{
unsigned num_packed, num_headers, length, length1, length2, extradata_alloc;
int ret;
uint8_t *ptr;
if (packed_headers_end - packed_headers < 9) {
@@ -264,9 +265,9 @@ parse_packed_headers(AVFormatContext *s,
* -- AV_INPUT_BUFFER_PADDING_SIZE required */
extradata_alloc = length + length/255 + 3 + AV_INPUT_BUFFER_PADDING_SIZE;
if (ff_alloc_extradata(par, extradata_alloc)) {
if ((ret = ff_alloc_extradata(par, extradata_alloc)) < 0) {
av_log(s, AV_LOG_ERROR, "Out of memory\n");
return AVERROR(ENOMEM);
return ret;
}
ptr = par->extradata;
*ptr++ = 2;