summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-10-22 19:38:58 +0200
committersfan5 <sfan5@live.de>2023-10-23 20:33:51 +0200
commit1805681aaba22aa19a27ecfdb639c983d91f83e6 (patch)
tree755dfebed879c474f6f55b5e7b6efbf66b5693c9 /options
parent907443686242dfb9636ac5b604581f484e5fca7f (diff)
downloadmpv-1805681aaba22aa19a27ecfdb639c983d91f83e6.tar.bz2
mpv-1805681aaba22aa19a27ecfdb639c983d91f83e6.tar.xz
m_option: initialize m_option_value union properly
C standard says that `= {0}` activates and initializes first member of union. We expect whole union to be zeroed, it is used as default value. Initialize union with one zeroed default instance to ensure proper init. Fixes: #12711
Diffstat (limited to 'options')
-rw-r--r--options/m_config_core.c4
-rw-r--r--options/m_config_frontend.c7
-rw-r--r--options/m_option.h5
-rw-r--r--options/m_property.c6
4 files changed, 12 insertions, 10 deletions
diff --git a/options/m_config_core.c b/options/m_config_core.c
index 6a7b0a065f..4e488ca01d 100644
--- a/options/m_config_core.c
+++ b/options/m_config_core.c
@@ -105,8 +105,6 @@ struct m_group_data {
uint64_t ts; // timestamp of the data copy
};
-static const union m_option_value default_value = {0};
-
static void add_sub_group(struct m_config_shadow *shadow, const char *name_prefix,
int parent_group_index, int parent_ptr,
const struct m_sub_options *subopts);
@@ -241,7 +239,7 @@ const void *m_config_shadow_get_opt_default(struct m_config_shadow *shadow,
if (subopt->defaults)
return (char *)subopt->defaults + opt->offset;
- return &default_value;
+ return &m_option_value_default;
}
void *m_config_cache_get_opt_data(struct m_config_cache *cache, int32_t id)
diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c
index 44cb9fd834..e95b350849 100644
--- a/options/m_config_frontend.c
+++ b/options/m_config_frontend.c
@@ -749,7 +749,7 @@ int m_config_set_option_cli(struct m_config *config, struct bstr name,
BSTR_P(name), BSTR_P(param), flags);
}
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
// Some option types are "impure" and work on the existing data.
// (Prime examples: --vf-add, --sub-file)
@@ -783,7 +783,7 @@ int m_config_set_option_node(struct m_config *config, bstr name,
// Do this on an "empty" type to make setting the option strictly overwrite
// the old value, as opposed to e.g. appending to lists.
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
if (data->format == MPV_FORMAT_STRING) {
bstr param = bstr0(data->u.string);
@@ -868,9 +868,8 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
}
char *def = NULL;
const void *defptr = m_config_get_co_default(config, co);
- const union m_option_value default_value = {0};
if (!defptr)
- defptr = &default_value;
+ defptr = &m_option_value_default;
if (defptr)
def = m_option_pretty_print(opt, defptr);
if (def) {
diff --git a/options/m_option.h b/options/m_option.h
index 3e86485930..e62fa0fc26 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -256,6 +256,11 @@ union m_option_value {
struct m_channels channels;
};
+// Keep fully zeroed instance of m_option_value to use as a default value, before
+// any specific union member is used. C standard says that `= {0}` activates and
+// initializes only the first member of the union, leaving padding bits undefined.
+static const union m_option_value m_option_value_default;
+
////////////////////////////////////////////////////////////////////////////
struct m_option_action {
diff --git a/options/m_property.c b/options/m_property.c
index 7667dd6161..1b76f05e7d 100644
--- a/options/m_property.c
+++ b/options/m_property.c
@@ -38,7 +38,7 @@ static int m_property_multiply(struct mp_log *log,
const struct m_property *prop_list,
const char *property, double f, void *ctx)
{
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
struct m_option opt = {0};
int r;
@@ -98,7 +98,7 @@ static int do_action(const struct m_property *prop_list, const char *name,
int m_property_do(struct mp_log *log, const struct m_property *prop_list,
const char *name, int action, void *arg, void *ctx)
{
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
int r;
struct m_option opt = {0};
@@ -562,7 +562,7 @@ int m_property_read_list(int action, void *arg, int count,
r = get_item(n, M_PROPERTY_GET_TYPE, &opt, ctx);
if (r != M_PROPERTY_OK)
goto err;
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
r = get_item(n, M_PROPERTY_GET, &val, ctx);
if (r != M_PROPERTY_OK)
goto err;