[Ffmpeg-devel] clip_uint8

Aurelien Jacobs aurel
Sun Apr 30 19:49:30 CEST 2006


On Fri, 28 Apr 2006 17:58:56 +0200
Panagiotis Issaris <takis.issaris at uhasselt.be> wrote:

> Hi,
> 
> The clip function clips between the amin and amax values given as parameters, 
> the clip_uint8 function, actually behaves a bit differently. The lower bound
> is indeed 0 as the uint8 postfix in the name implies, but upper values (values 
> higher then 255) are returned as -1. This works if the value which stores the 
> returned value is uint8, but in other cases will cause strange behavior imho.
> 
> [...]
> 
> Changing the return type to uint8_t fixes this, or was the -1 
> return value intentional?
> 
> diff --git a/libavutil/common.h b/libavutil/common.h
> index d8f2c40..92c0d08 100644
> --- a/libavutil/common.h
> +++ b/libavutil/common.h
> @@ -437,7 +437,7 @@ static inline int clip(int a, int amin,
>          return a;
>  }
> 
> -static inline int clip_uint8(int a)
> +static inline uint8_t clip_uint8(int a)
>  {
>      if (a&(~255)) return (-a)>>31;
>      else          return a;

I verified the issue, tested your patch and applied it.

Aurel





More information about the ffmpeg-devel mailing list