From 4075add5b45d15e084e68ea39eda6959ae052f7f Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Thu, 6 Mar 2025 13:46:51 -0500 Subject: [PATCH] plug-ins/help: fix crash when locale is NULL Due to recent changes locale could become NULL when no manual for a certain locale was found. We fix this by always checking locale first. While working at this, I realized that nowadays we don't need a second loop when the specified help-id was not found. Even if a certain help-id is not translated, an untranslated page is always available when an English page is present. So just reference the help_missing page for the locale we found instead of doing another loop over the locales. --- plug-ins/help/gimphelpdomain.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/plug-ins/help/gimphelpdomain.c b/plug-ins/help/gimphelpdomain.c index 2e08d00339..53d6d081c4 100644 --- a/plug-ins/help/gimphelpdomain.c +++ b/plug-ins/help/gimphelpdomain.c @@ -145,26 +145,24 @@ gimp_help_domain_map (GimpHelpDomain *domain, if (fatal_error) *fatal_error = FALSE; - /* first pass: look for a reference matching the help_id */ + /* Look for a reference matching the help_id */ for (list = help_locales; list && !ref; list = list->next) { locale = gimp_help_domain_lookup_locale (domain, (const gchar *) list->data, progress); - if (locale != NULL) - ref = gimp_help_locale_map (locale, help_id); + if (locale) + { + ref = gimp_help_locale_map (locale, help_id); + /* It doesn't make sense to keep looking since all available locales + * have the same pages available. If the first locale present + * doesn't have it, the others won't have it either. */ + if (! ref) + ref = locale->help_missing; + } } - /* second pass: look for a fallback */ - for (list = help_locales; list && !ref; list = list->next) - { - locale = gimp_help_domain_lookup_locale (domain, - (const gchar *) list->data, - progress); - ref = locale->help_missing; - } - - if (ret_locale) + if (ret_locale && locale) *ret_locale = locale; if (ref) @@ -186,7 +184,7 @@ gimp_help_domain_map (GimpHelpDomain *domain, locale = gimp_help_domain_lookup_locale (domain, GIMP_HELP_DEFAULT_LOCALE, NULL); - if (! domain_locale_parse (domain, locale, NULL, &error)) + if (locale && ! domain_locale_parse (domain, locale, NULL, &error)) { switch (error->code) {