On 26.05.2015 15:59, Vittorio Giovara wrote:
> On Tue, May 26, 2015 at 2:44 PM, Luca Barbato <[email protected]> wrote:
>> On 26/05/15 15:24, Vittorio Giovara wrote:
>>>
>>> ---
>>>   libavformat/avio_internal.h | 7 +++++++
>>>   libavformat/aviobuf.c       | 8 ++++++++
>>>   2 files changed, 15 insertions(+)
>>>
>>> diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
>>> index c8630ab..aff5564 100644
>>> --- a/libavformat/avio_internal.h
>>> +++ b/libavformat/avio_internal.h
>>> @@ -85,6 +85,13 @@ int ffio_rewind_with_probe_data(AVIOContext *s,
>>> unsigned char *buf, int buf_size
>>>
>>>   uint64_t ffio_read_varlen(AVIOContext *bc);
>>>
>>> +/**
>>> + * Read size bytes from AVIOContext into buf.
>>> + * Check that exactly size bytes have been read.
>>> + * @return number of bytes read or AVERROR
>>> + */
>>> +int ffio_read_size(AVIOContext *s, unsigned char *buf, int size);
>>> +
>>>   /** @warning must be called before any I/O */
>>>   int ffio_set_buf_size(AVIOContext *s, int buf_size);
>>>
>>> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
>>> index 59f807c..d3e3452 100644
>>> --- a/libavformat/aviobuf.c
>>> +++ b/libavformat/aviobuf.c
>>> @@ -496,6 +496,14 @@ int avio_read(AVIOContext *s, unsigned char *buf, int
>>> size)
>>>       return size1 - size;
>>>   }
>>>
>>> +int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
>>> +{
>>> +    int ret = avio_read(s, buf, size);
>>> +    if (ret != size)
>>> +        return AVERROR_INVALIDDATA;

I like the idea of having such a function and I think most uses of avio_read
should be replaced with it.
What do you think about making it public and recommending it over using
avio_read directly?

>> you might do
>>
>> if (ret < 0)
>>     return ret;
>> if (ret != size)
>>     return AVERROR_INVALIDDATA;
> 
> umh yeah it's better.

That's the best way to deal with the avio_read return value, but I didn't
want to add this boilerplate everywhere...

Best regards,
Andreas

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to