gkrellmms got into an endless for(;;) loop in string_to_utf8() when run
under UTF-8 locales and playing songs with artists or titles containing
characters outside of 7bit ASCII.
Calling g_locale_to_utf8() in string_to_utf8() was wrong under UTF-8
locales since libxmms always returns ISO-8859-* and never UTF-8.
This patch fixes the issue for me.
In the worst case, wrong characters might be displayed if xmms and
gkrellm run under different locales.
I simply deleted the for(;;) loop instead of trying to understand what
it should have done.
I didn't understand why the g_filename_to_utf8() was there, and
therefore deleted it.
But if something of the above is wrong, my patch should at least help
with creating a proper patch.
I only tested ISO-8859-* and UTF-8 locales, others like the non-UTF-8
Asien locales have not been tested.
playlist.c | 48 ++++++++++++++----------------------------------
1 file changed, 14 insertions(+), 34 deletions(-)
--- playlist.c.old 2007-01-16 13:55:22.000000000 +0100
+++ playlist.c 2007-01-16 14:29:59.000000000 +0100
@@ -49,11 +49,8 @@ static gint playlist_length = -1;
* The argument string is freed and the new converted version is returned
* */
static gchar *
-string_to_utf8(gchar *str, gboolean is_filename) {
+string_to_utf8(gchar *str) {
gchar *result = NULL;
- GError *error = NULL;
- gsize read = 0, lastread = -1;
-
if (str == NULL)
return NULL;
@@ -61,30 +58,14 @@ string_to_utf8(gchar *str, gboolean is_f
if (g_utf8_validate(str, -1, NULL)) {
return str;
}
- if (is_filename) {
- result = g_filename_to_utf8(str, -1, NULL, NULL, NULL);
- }
- if (result == NULL) {
- /* filename to utf8 failed, assume file encoding was local */
- for (;;) {
- result = g_locale_to_utf8(str, -1, &read, NULL, &error);
- if (result != NULL)
- break;
-
- if (G_CONVERT_ERROR_ILLEGAL_SEQUENCE == error->code) {
- /* ensure we progress through the string */
- if (read == lastread) read++;
- str[read] = '?';
- lastread = read;
- } else {
- /* unknown error, giving up */
- g_error_free(error);
- break;
- }
- g_error_free(error);
- error = NULL;
- }
- }
+
+ /* assume encoding was ISO-8859-* */
+ result = g_locale_to_utf8(str, -1, NULL, NULL, NULL);
+
+ /* in an UTF-8 locale, XMMS returns ISO-8859-1 */
+ if (result == NULL)
+ result = g_convert(str, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+
g_free(str);
return result;
}
@@ -119,9 +100,9 @@ void update_playlist_position(void) {
current_time = xmms_remote_get_playlist_time(xmms_session,
current_position -1);
- current_file = string_to_utf8(current_file, TRUE);
+ current_file = string_to_utf8(current_file);
- current_title = string_to_utf8(current_title, FALSE);
+ current_title = string_to_utf8(current_title);
if (current_title == NULL && current_file != NULL) {
current_title = g_strdup(current_file);
}
@@ -166,7 +147,7 @@ load_playlist(void) {
empty_playlist();
return load_playlist();
}
- filename = string_to_utf8(filename, TRUE);
+ filename = string_to_utf8(filename);
while (gtk_events_pending())
gtk_main_iteration();
@@ -175,7 +156,7 @@ load_playlist(void) {
if (always_load_info) {
title = xmms_remote_get_playlist_title(xmms_session, i);
if (title != NULL) {
- title = string_to_utf8(title, FALSE);
+ title = string_to_utf8(title);
}
time = xmms_remote_get_playlist_time(xmms_session, i);
gtk_list_store_set(playlist,&iter,
@@ -212,8 +193,7 @@ update_playlist(void) {
return TRUE;
}
filename = string_to_utf8(
- xmms_remote_get_playlist_file(xmms_session,current_position-1),
- TRUE
+ xmms_remote_get_playlist_file(xmms_session,current_position-1)
);
if (filename == NULL || strcmp(pl_get_current_file(), filename)) {
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]