summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Toso <me@victortoso.com>2018-09-03 12:47:29 +0200
committerVictor Toso <me@victortoso.com>2018-10-02 16:24:40 +0200
commitaf568e8ca8e0bc65cffa0a1c6859e0ec9c9f4b13 (patch)
treecdfe19e5feb887a24632919fbe425134d3514f4f /src
parentbbad302f7fa63ccc0d13ba307e6e986a8271c3ae (diff)
downloadgrilo-af568e8ca8e0bc65cffa0a1c6859e0ec9c9f4b13.tar.gz
core: Fix return value of invalid argument on grl_data_*_for_id()
If g_value_type_transformable () fails, we can't take the @GValue for that given metadata-key. Return FALSE instead of TRUE. Signed-off-by: Victor Toso <victortoso@gnome.org>
Diffstat (limited to 'src')
-rw-r--r--src/data/grl-data.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index e9317ae..27f8229 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -657,6 +657,7 @@ grl_data_set_for_id (GrlData *data, const gchar *key_name, const GValue *value)
{
GrlRegistry *registry;
GrlKeyID key_id;
+ GType value_type;
if (value == NULL)
return TRUE;
@@ -666,14 +667,22 @@ grl_data_set_for_id (GrlData *data, const gchar *key_name, const GValue *value)
registry = grl_registry_get_default ();
key_id = grl_registry_lookup_metadata_key (registry, key_name);
+ value_type = G_VALUE_TYPE (value);
if (key_id != GRL_METADATA_KEY_INVALID) {
+ GType key_type = grl_registry_lookup_metadata_key_type (registry, key_id);
+ if (!g_value_type_transformable (value_type, key_type)) {
+ GRL_WARNING ("Value type %s can't be set to existing metadata-key of type %s",
+ g_type_name (value_type),
+ g_type_name (key_type));
+ return FALSE;
+ }
grl_data_set (data, key_id, value);
return TRUE;
}
GRL_DEBUG ("%s is not a registered metadata-key", key_name);
- key_id = grl_registry_register_metadata_key_for_type(registry, key_name, G_VALUE_TYPE (value));
+ key_id = grl_registry_register_metadata_key_for_type(registry, key_name, value_type);
if (key_id != GRL_METADATA_KEY_INVALID)
grl_data_set (data, key_id, value);
@@ -705,6 +714,7 @@ grl_data_add_for_id (GrlData *data, const gchar *key_name, const GValue *value)
{
GrlRegistry *registry;
GrlKeyID key_id;
+ GType value_type;
if (value == NULL)
return TRUE;
@@ -714,16 +724,25 @@ grl_data_add_for_id (GrlData *data, const gchar *key_name, const GValue *value)
registry = grl_registry_get_default ();
key_id = grl_registry_lookup_metadata_key (registry, key_name);
+ value_type = G_VALUE_TYPE (value);
if (key_id == GRL_METADATA_KEY_INVALID) {
GRL_DEBUG ("%s is not a registered metadata-key", key_name);
- key_id = grl_registry_register_metadata_key_for_type (registry, key_name, G_VALUE_TYPE (value));
+ key_id = grl_registry_register_metadata_key_for_type (registry, key_name, value_type);
if (key_id == GRL_METADATA_KEY_INVALID) {
return FALSE;
}
+ } else {
+ GType key_type = grl_registry_lookup_metadata_key_type (registry, key_id);
+ if (!g_value_type_transformable (value_type, key_type)) {
+ GRL_WARNING ("Value type %s can't be set to existing metadata-key of type %s",
+ g_type_name (value_type),
+ g_type_name (key_type));
+ return FALSE;
+ }
}
- switch (G_VALUE_TYPE (value)) {
+ switch (value_type) {
case G_TYPE_INT:
grl_data_add_int (data, key_id, g_value_get_int (value));
break;