[vte/vte-0-36] iconv: Fix broken _vte_conv_utf8_strlen



commit ef06c336f28d5c4472a886f4374631cf6e0ad4f8
Author: Egmont Koblinger <egmont gmail com>
Date:   Fri May 16 13:25:39 2014 +0200

    iconv: Fix broken _vte_conv_utf8_strlen
    
    (cherry picked from commit 3287a66f02edd3f26e5da708d1c3d36b3418a23c)

 src/vteconv.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/vteconv.c b/src/vteconv.c
index 265d6f7..a709668 100644
--- a/src/vteconv.c
+++ b/src/vteconv.c
@@ -46,11 +46,11 @@ static glong
 _vte_conv_utf8_strlen(const gchar *p, gssize max)
 {
        const gchar *q = p + max;
-       glong length = -1;
-       do {
-               length++;
+        glong length = 0;
+        while (p < q) {
                p = g_utf8_next_char(p);
-       } while (p < q);
+                length++;
+        }
        return length;
 }
 
@@ -395,6 +395,9 @@ main(int argc, char **argv)
        char mbyte_test_break[] = {0xe2, 0xe2, 0xe2};
        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);
        g_assert(i == 4);
        i = _vte_conv_utf8_strlen("\0A\0\0", 4);
@@ -403,8 +406,12 @@ main(int argc, char **argv)
        g_assert(i == 4);
        i = _vte_conv_utf8_strlen("A\0B\0", 4);
        g_assert(i == 4);
+        i = _vte_conv_utf8_strlen("ABCD", 4);
+        g_assert(i == 4);
        i = _vte_conv_utf8_strlen("ABCDE", 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. */
        clear(wide_test, narrow_test);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]