avutil/mastering_display_metadata: set a sane default value for AVRational fields

Prevent potential divisions by 0 when using them immediately after allocation.

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
James Almer 2024-06-18 16:12:23 -03:00 committed by Paul B Mahol
parent e9e8ba6767
commit 59d26f301c
2 changed files with 16 additions and 2 deletions

View File

@ -25,9 +25,20 @@
#include "mastering_display_metadata.h"
#include "mem.h"
static void get_defaults(AVMasteringDisplayMetadata *mastering)
{
for (int i = 0; i < 3; i++)
for (int j = 0; j < 2; j++)
mastering->display_primaries[i][j] = (AVRational) { 0, 1 };
mastering->white_point[0] =
mastering->white_point[1] =
mastering->min_luminance =
mastering->max_luminance = (AVRational) { 0, 1 };
}
AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void)
{
return av_mallocz(sizeof(AVMasteringDisplayMetadata));
return av_mastering_display_metadata_alloc_size(NULL);
}
AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *size)
@ -36,6 +47,8 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *siz
if (!mastering)
return NULL;
get_defaults(mastering);
if (size)
*size = sizeof(*mastering);
@ -51,6 +64,7 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFra
return NULL;
memset(side_data->data, 0, sizeof(AVMasteringDisplayMetadata));
get_defaults((AVMasteringDisplayMetadata *)side_data->data);
return (AVMasteringDisplayMetadata *)side_data->data;
}

View File

@ -80,7 +80,7 @@
#define LIBAVUTIL_VERSION_MAJOR 59
#define LIBAVUTIL_VERSION_MINOR 24
#define LIBAVUTIL_VERSION_MICRO 101
#define LIBAVUTIL_VERSION_MICRO 102
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \