summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-02 19:00:34 +0200
committerwm4 <wm4@nowhere>2016-09-02 21:21:47 +0200
commit9770ce6c44cd26e7b9e5b525c3222281d32dcb6f (patch)
tree092ed3f229b658126777dfd9fdf15d4cad976f69 /options
parentb92d3b6d4486aa2630e7e3ae87506b9870638afa (diff)
downloadmpv-9770ce6c44cd26e7b9e5b525c3222281d32dcb6f.tar.bz2
mpv-9770ce6c44cd26e7b9e5b525c3222281d32dcb6f.tar.xz
m_config: make sure profile values are never NULL
Apparently this was supposed to be handled - but badly at best. Make unset values always have the value "" instead of NULL to avoid special-cases. In particular, this fixes passing NULL to a %s format specifier to printf in show_profile(). Glibc prints this as "(null)", but it's undefined behavior, and other libcs can crash.
Diffstat (limited to 'options')
-rw-r--r--options/m_config.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 125702c362..f3bbe7d8c9 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -943,7 +943,7 @@ struct m_profile *m_config_add_profile(struct m_config *config, char *name)
void m_profile_set_desc(struct m_profile *p, bstr desc)
{
talloc_free(p->desc);
- p->desc = bstrdup0(p, desc);
+ p->desc = bstrto0(p, desc);
}
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
@@ -955,8 +955,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
if (i < 0)
return i;
p->opts = talloc_realloc(p, p->opts, char *, 2 * (p->num_opts + 2));
- p->opts[p->num_opts * 2] = bstrdup0(p, name);
- p->opts[p->num_opts * 2 + 1] = bstrdup0(p, val);
+ p->opts[p->num_opts * 2] = bstrto0(p, name);
+ p->opts[p->num_opts * 2 + 1] = bstrto0(p, val);
p->num_opts++;
p->opts[p->num_opts * 2] = p->opts[p->num_opts * 2 + 1] = NULL;
return 1;
@@ -1005,8 +1005,7 @@ struct mpv_node m_config_get_profiles(struct m_config *config)
for (int n = 0; n < profile->num_opts; n++) {
struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP);
node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]);
- if (profile->opts[n * 2 + 1])
- node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]);
+ node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]);
}
}