Skip to content

Commit 9b0a03a

Browse files
[[ Bug 14413 ]] Fix UTF-8 <-> native conversion on Linux
1 parent b36f5c4 commit 9b0a03a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

libexternal/src/unxsupport.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ char *string_to_utf8(const char *p_string)
3535
unsigned int v;
3636
v = ((unsigned char *)p_string)[i];
3737

38-
if (v < 128)
38+
if (v < 128)
3939
t_utf8_string[j++] = v;
4040
else
4141
{
42-
t_utf8_string[j++] = 0xC0 | (v >> 5);
43-
t_utf8_string[j++] = 0x80 | (v & 63);
42+
// SN-2015-03-11: [[ Bug 14413 ]] Do the expected shift
43+
t_utf8_string[j++] = (0xC0 | (v >> 6));
44+
t_utf8_string[j++] = (0x80 | (v & 63));
4445
}
45-
}
46+
}
4647

4748
t_utf8_string[j] = '\0';
4849

@@ -57,20 +58,21 @@ char *string_from_utf8(const char* p_utf8_string)
5758
int i, j, t_error;
5859
t_error = 0;
5960

60-
for (i = 0, j = 0; p_string[i] != '\0' && !t_error;)
61+
for (i = 0, j = 0; p_utf8_string[i] != '\0' && !t_error;)
6162
{
6263
unsigned char t_first_char;
63-
t_first_char = ((unsigned char *)p_utf8_string)[i++];
64+
t_first_char = ((unsigned char *)p_utf8_string)[i++];
6465

6566
if (t_first_char < 128)
6667
t_iso_string[j++] = t_first_char;
67-
else if (p_string[i] != '\0')
68+
else if (p_utf8_string[i] != '\0')
6869
{
69-
unsigned char t_second_char;
70+
unsigned char t_second_char;
7071
t_second_char = p_utf8_string[i++];
7172

72-
t_iso_string[j++] = ((t_first_char & 0xBF) << 5)
73-
| ((t_second_char & 0x63);
73+
// SN-2015-03-11: [[ Bug 14413 ]] Take the 6 right bit of the first char.
74+
t_iso_string[j++] = ((t_first_char & 0x3F) << 6)
75+
| (t_second_char & 0x63);
7476
}
7577
else
7678
t_error = true;

0 commit comments

Comments
 (0)