[FFmpeg-devel] [PATCH 1/3] avutil/ambient_viewing_environment: set a sane default value for AVRational fields

James Almer jamrial at gmail.com
Thu Jun 20 18:54:17 EEST 2024


On 6/18/2024 4:20 PM, James Almer wrote:
> Prevent potential divisions by 0 when using them immediately after allocation.
> 
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>   libavutil/ambient_viewing_environment.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/libavutil/ambient_viewing_environment.c b/libavutil/ambient_viewing_environment.c
> index c47458cfa8..e359727776 100644
> --- a/libavutil/ambient_viewing_environment.c
> +++ b/libavutil/ambient_viewing_environment.c
> @@ -21,6 +21,13 @@
>   #include "ambient_viewing_environment.h"
>   #include "mem.h"
>   
> +static void get_defaults(AVAmbientViewingEnvironment *env)
> +{
> +    env->ambient_illuminance =
> +    env->ambient_light_x     =
> +    env->ambient_light_y     = (AVRational) { 0, 1 };
> +}
> +
>   AVAmbientViewingEnvironment *av_ambient_viewing_environment_alloc(size_t *size)
>   {
>       AVAmbientViewingEnvironment *env =
> @@ -28,6 +35,8 @@ AVAmbientViewingEnvironment *av_ambient_viewing_environment_alloc(size_t *size)
>       if (!env)
>           return NULL;
>   
> +    get_defaults(env);
> +
>        if (size)
>           *size = sizeof(*env);
>   
> @@ -44,6 +53,7 @@ AVAmbientViewingEnvironment *av_ambient_viewing_environment_create_side_data(AVF
>           return NULL;
>   
>       memset(side_data->data, 0, side_data->size);
> +    get_defaults((AVAmbientViewingEnvironment *)side_data->data);
>   
>       return (AVAmbientViewingEnvironment *)side_data->data;
>   }

Will apply the set soon if nobody objectx.


More information about the ffmpeg-devel mailing list