summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/cfgfiles.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index 59761bc5..7f6bc3ed 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -613,16 +613,19 @@ convert_with_fallback (const char *str, const char *fallback)
 {
 	char *utf;
 
-	utf = g_locale_to_utf8 (str, -1, 0, 0, 0);
+#ifndef WIN32
+	/* On non-Windows, g_get_user_name and g_get_real_name return a string in system locale, so convert it to utf-8. */
+	utf = g_locale_to_utf8 (str, -1, NULL, NULL, 0);
+
+	g_free (str);
+
+	/* The returned string is NULL if conversion from locale to utf-8 failed for any reason. Return the fallback. */
 	if (!utf)
-	{
-		/* this can happen if CHARSET envvar is set wrong */
-		/* maybe it's already utf8 (breakage!) */
-		if (!g_utf8_validate (str, -1, NULL))
-			utf = g_strdup (fallback);
-		else
-			utf = g_strdup (str);
-	}
+		utf = g_strdup (fallback);
+#else
+	/* On Windows, they return a string in utf-8, so don't do anything to it. The fallback isn't needed. */
+	utf = str;
+#endif
 
 	return utf;
 }
@@ -739,13 +742,13 @@ load_default_config(void)
 
 	username = g_get_user_name ();
 	if (!username)
-		username = "root";
+		username = g_strdup ("root");
 
 	/* We hid Real name from the Network List, so don't use the user's name unnoticeably */
 	/* realname = g_get_real_name ();
 	if ((realname && realname[0] == 0) || !realname)
 		realname = username; */
-	realname = "realname";
+	realname = g_strdup ("realname");
 
 	username = convert_with_fallback (username, "username");
 	realname = convert_with_fallback (realname, "realname");