mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <ctype>'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 <sergey.starosek@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9f6b8ca89a
commit
4401132836
4 changed files with 21 additions and 21 deletions
|
@ -386,7 +386,7 @@ static void percent(char *buffer, void *_fraction)
|
|||
case FLOAT:
|
||||
/* Turn fractions into percent unless explicit.. */
|
||||
if (val <= 1.0) {
|
||||
while (isspace(*end))
|
||||
while (g_ascii_isspace(*end))
|
||||
end++;
|
||||
if (*end != '%')
|
||||
val *= 100;
|
||||
|
@ -437,10 +437,10 @@ static void utf8_string(char *buffer, void *_res)
|
|||
{
|
||||
int size;
|
||||
char *res;
|
||||
while (isspace(*buffer))
|
||||
while (g_ascii_isspace(*buffer))
|
||||
buffer++;
|
||||
size = strlen(buffer);
|
||||
while (size && isspace(buffer[size-1]))
|
||||
while (size && g_ascii_isspace(buffer[size-1]))
|
||||
size--;
|
||||
if (!size)
|
||||
return;
|
||||
|
@ -926,7 +926,7 @@ static degrees_t parse_degrees(char *buf, char **end)
|
|||
int sign = 1, decimals = 6, value = 0;
|
||||
degrees_t ret;
|
||||
|
||||
while (isspace(*buf))
|
||||
while (g_ascii_isspace(*buf))
|
||||
buf++;
|
||||
switch (*buf) {
|
||||
case '-':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue