On 10/17/2019 5:29 AM, Andreas Rheinhardt wrote:
> bytestream2_get_bytes_left returns an unsigned int; as a result,
> it returns big positive numbers if an overread already happened,
> making it unsuitable for scenarios where one wants to allow this
> (because the buffer is actually padded so that no segfaults can
> happen). So add a function returning ptrdiff_t for this purpose;
> given that it is intended to be used with the unsafe functions,
> it has an "u" suffix, although it is not unsafe by itself.
>
> Signed-off-by: Andreas Rheinhardt <[email protected]>
> ---
> libavcodec/bytestream.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
> index 7be7fc22fc..18774524cf 100644
> --- a/libavcodec/bytestream.h
> +++ b/libavcodec/bytestream.h
> @@ -156,6 +156,11 @@ static av_always_inline unsigned int
> bytestream2_get_bytes_left(GetByteContext *
> return g->buffer_end - g->buffer;
> }
>
> +static av_always_inline ptrdiff_t bytestream2_get_bytes_leftu(GetByteContext
> *g)
> +{
> + return g->buffer_end - g->buffer;
> +}
Just make bytestream2_get_bytes_left() return an int instead. It's what
get_bits_left() does, and it's used to detect overreads.
There's no need for a new function.
> +
> static av_always_inline unsigned int
> bytestream2_get_bytes_left_p(PutByteContext *p)
> {
> return p->buffer_end - p->buffer;
>
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".