[vlc-devel] [PATCH 3/4] vlc_common.h: Ensure clip_uint8_vlc returns an uint8_t
Rémi Denis-Courmont
remi at remlab.net
Thu Oct 22 17:23:04 CEST 2020
Le torstaina 22. lokakuuta 2020, 10.49.48 EEST Hugo Beauzée-Luyssen a écrit :
> Even though the modified branch is logically guaranteed to return a
> number that fits in an uint8, some compilers will complain that a signed
> 32 bits integer is returned
There are plenty of cases where we implicitly down-convert types.
Realistically, you'll have to turn that warning off or ignore it.
> ---
> include/vlc_common.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/vlc_common.h b/include/vlc_common.h
> index 323df74653..9742d2b943 100644
> --- a/include/vlc_common.h
> +++ b/include/vlc_common.h
> @@ -585,7 +585,7 @@ VLC_USED
> static inline uint8_t clip_uint8_vlc( int32_t a )
> {
> if( a&(~255) ) return (-a)>>31;
> - else return a;
> + else return (uint8_t)a;
> }
>
> /**
And the code is wrong with or without the patch. It overflows on INT32_MIN.
Also I'm not sure if shifting a *signed* 32-bit value by 31 bits is defined.
--
レミ・デニ-クールモン
http://www.remlab.net/
More information about the vlc-devel
mailing list