From 4401132836fdb8798c4dbe07b5c7ae1e0112f248 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 7 Mar 2013 21:16:31 +0200 Subject: Fix potentially broken white space truncation on certain Windows versions Testing the Planner in Subsurface on a Windows XP SP3 installation, shows corrupted UTF-8 strings in the case of Cyrillic locales, but possibly others as well. Instead limited to the Planner, this affects the entire application. After some examination it appears that 's isspace() in MSVC on the tested version of Windows is broken for some UTF-8 characters, after enabling the user locale using: setlocale(LC_ALL, ""); For example, characters such as the Cyrillic capital "BE" are defined as: 0xD091, where isspace() for the first byte returns 0x08, which is the bytemask for C1_SPACE and the character is treated as space. After a byte is treated as space, it is usually discarded from a UTF-8 character/string, where if only one byte left, corrupting the entire string. In Subsurface, usages of string trimming are present in multiple locations, so to make this work try to use GLib's g_ascii_isspace(), which is a locale agnostic version of isspace(). Affected versions of Windows could be everything up to XP SP3, but not apparently Vista. Reported-by: Sergey Starosek Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- save-xml.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'save-xml.c') diff --git a/save-xml.c b/save-xml.c index a23fb10a3..7ae71dd57 100644 --- a/save-xml.c +++ b/save-xml.c @@ -125,12 +125,12 @@ static void show_utf8(FILE *f, const char *text, const char *pre, const char *po if (!text) return; - while (isspace(*text)) + while (g_ascii_isspace(*text)) text++; len = strlen(text); if (!len) return; - while (len && isspace(text[len-1])) + while (len && g_ascii_isspace(text[len-1])) len--; /* FIXME! Quoting! */ fputs(pre, f); -- cgit v1.2.3-70-g09d2