From 4c7c2b75e56626a1270cd96f8951f0163ceb5451 Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 3 Mar 2021 10:54:38 +0100 Subject: [PATCH] babl: do not append space to the format name when explicitly set. When a format is named explicitly by the caller, we should just keep the same name, not tweak it. Generating a name is only valid when no explicit name is given. Moreover this is the behavior as described in the docs of babl_format_new(): > If no name is provided a (long) descriptive name is used. (which usually implies that with a name provided, this one will be used instead of a generated name) This is especially important for palette formats for which name is mostly not descriptive anyway (either caller-set or generated by babl with incremental number) and this fixes a bug when calling babl_new_palette_with_space() with the same name and space would fail to find the already created formats (yet would find the models and return NULL for both formats) because it would search without the space description appended. Yet the docs of babl_new_palette*() clearly says as well: > If you pass in the same name the previous formats will be provided > again. Moreover we actually already tweak a bit the palette format name by appending the space pointer. No need to tweak it twice appending the same information (space) in a different way. See also: https://gitlab.gnome.org/GNOME/gimp/-/issues/6501 --- babl/babl-format.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/babl/babl-format.c b/babl/babl-format.c index 2e4e3d7..c9a1175 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -468,16 +468,18 @@ babl_format_new (const void *first_arg, va_end (varg); if (!name) - name = create_name (model, components, component, type); + { + name = create_name (model, components, component, type); - if (space != babl_space ("sRGB")) - { - char *new_name = babl_malloc (strlen (name) + - strlen (babl_get_name ((Babl*)space)) + 1); - sprintf (new_name, "%s-%s", name, babl_get_name ((Babl*)space)); - babl_free (name); - name = new_name; - } + if (space != babl_space ("sRGB")) + { + char *new_name = babl_malloc (strlen (name) + + strlen (babl_get_name ((Babl*)space)) + 1); + sprintf (new_name, "%s-%s", name, babl_get_name ((Babl*)space)); + babl_free (name); + name = new_name; + } + } if (!model) { -- 2.30.2