[gnome-initial-setup/mcatanzaro/uselocale-error-checking] Check for errors from newlocale()
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/mcatanzaro/uselocale-error-checking] Check for errors from newlocale()
- Date: Tue, 4 Jun 2019 21:22:18 +0000 (UTC)
commit a690f778d77746f8f7dab4d37c10d07d2849424a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Tue Jun 4 16:12:29 2019 -0500
Check for errors from newlocale()
We accidentally deleted all locales from Fedora in yesterday's rawhide
build. This revealed a bug in my uselocale changes to
gnome-initial-setup: when a locale is missing from the system, g-i-s
will crash rather than degrading gracefully. This is easy to fix, so
let's do so.
We also ignore errors from uselocale(), but this is probably OK because
the only possible error is passing in an invalid locale object, which is
no longer possible after this commit.
https://bugzilla.redhat.com/show_bug.cgi?id=1716691
gnome-initial-setup/gis-driver.c | 9 ++++++++-
gnome-initial-setup/pages/language/gis-welcome-widget.c | 7 +++++++
2 files changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index c1ccee2..a377f55 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -23,8 +23,9 @@
#include "gnome-initial-setup.h"
-#include <stdlib.h>
+#include <errno.h>
#include <locale.h>
+#include <stdlib.h>
#include <gdm/gdm-client.h>
#include "cc-common-language.h"
@@ -199,6 +200,12 @@ gis_driver_set_user_language (GisDriver *driver, const gchar *lang_id, gboolean
if (update_locale)
{
locale_t locale = newlocale (LC_MESSAGES_MASK, lang_id, (locale_t) 0);
+ if (locale == (locale_t) 0)
+ {
+ g_warning ("Failed to create locale %s: %s", lang_id, g_strerror (errno));
+ return;
+ }
+
uselocale (locale);
if (priv->locale != (locale_t) 0 && priv->locale != LC_GLOBAL_LOCALE)
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.c
b/gnome-initial-setup/pages/language/gis-welcome-widget.c
index 37b000f..7777638 100644
--- a/gnome-initial-setup/pages/language/gis-welcome-widget.c
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "gis-welcome-widget.h"
+#include <errno.h>
#include <locale.h>
#include <glib/gi18n.h>
@@ -116,6 +117,12 @@ welcome (const char *locale_id)
char *welcome;
locale = newlocale (LC_MESSAGES_MASK, locale_id, (locale_t) 0);
+ if (locale == (locale_t) 0)
+ {
+ g_warning ("Failed to create locale %s: %s", locale_id, g_strerror (errno));
+ return "Welcome!";
+ }
+
old_locale = uselocale (locale);
/* Translators: This is meant to be a warm, engaging welcome message,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]