Commit 3287a66f authored by Egmont Koblinger's avatar Egmont Koblinger

iconv: Fix broken _vte_conv_utf8_strlen

parent c745ac44
...@@ -46,11 +46,11 @@ static glong ...@@ -46,11 +46,11 @@ static glong
_vte_conv_utf8_strlen(const gchar *p, gssize max) _vte_conv_utf8_strlen(const gchar *p, gssize max)
{ {
const gchar *q = p + max; const gchar *q = p + max;
glong length = -1; glong length = 0;
do { while (p < q) {
length++;
p = g_utf8_next_char(p); p = g_utf8_next_char(p);
} while (p < q); length++;
}
return length; return length;
} }
...@@ -395,6 +395,9 @@ main(int argc, char **argv) ...@@ -395,6 +395,9 @@ main(int argc, char **argv)
char mbyte_test_break[] = {0xe2, 0xe2, 0xe2}; char mbyte_test_break[] = {0xe2, 0xe2, 0xe2};
int i; int i;
/* Test _vte_conv_utf8_strlen, especially where it differs from g_utf8_strlen. */
i = _vte_conv_utf8_strlen("", 0);
g_assert(i == 0);
i = _vte_conv_utf8_strlen("\0\0\0\0", 4); i = _vte_conv_utf8_strlen("\0\0\0\0", 4);
g_assert(i == 4); g_assert(i == 4);
i = _vte_conv_utf8_strlen("\0A\0\0", 4); i = _vte_conv_utf8_strlen("\0A\0\0", 4);
...@@ -403,8 +406,12 @@ main(int argc, char **argv) ...@@ -403,8 +406,12 @@ main(int argc, char **argv)
g_assert(i == 4); g_assert(i == 4);
i = _vte_conv_utf8_strlen("A\0B\0", 4); i = _vte_conv_utf8_strlen("A\0B\0", 4);
g_assert(i == 4); g_assert(i == 4);
i = _vte_conv_utf8_strlen("ABCD", 4);
g_assert(i == 4);
i = _vte_conv_utf8_strlen("ABCDE", 4); i = _vte_conv_utf8_strlen("ABCDE", 4);
g_assert(i == 4); g_assert(i == 4);
i = _vte_conv_utf8_strlen("\xC2\xA0\xC2\xA0", 4);
g_assert(i == 2);
/* Test g_iconv, no gunichar stuff. */ /* Test g_iconv, no gunichar stuff. */
clear(wide_test, narrow_test); clear(wide_test, narrow_test);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment