[tarantool-patches] Re: [PATCH] sql: LIKE/LENGTH process '\0'

i.koptelov ivan.koptelov at tarantool.org
Wed Feb 20 18:47:01 MSK 2019


Thanks to Alexander, I fixed my patch to use a function
from icu to count the length of the string.

Changes:


diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 233ea2901..8ddb9780f 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -149,16 +149,7 @@ utf8_char_count(const unsigned char *str, int byte_len)
 {
 	int symbol_count = 0;
 	for (int i = 0; i < byte_len;) {
-		if ((str[i] & 0x80) == 0)
-			i += 1;
-		else if ((str[i] & 0xe0) == 0xc0)
-			i += 2;
-		else if ((str[i] & 0xf0) == 0xe0)
-			i += 3;
-		else if ((str[i] & 0xf8) == 0xf0)
-			i += 4;
-		else
-			i += 1;
+		U8_FWD_1_UNSAFE(str, i);
 		symbol_count++;
 	}
 	return symbol_count;
diff --git a/test/sql-tap/badutf1.test.lua b/test/sql-tap/badutf1.test.lua
index 67c1071b3..d104efaa9 100755
--- a/test/sql-tap/badutf1.test.lua
+++ b/test/sql-tap/badutf1.test.lua
@@ -255,7 +255,7 @@ test:do_test(
         return test:execsql2("SELECT length('\x61\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80') AS x")
     end, {
         -- <badutf-3.5>
-        "X", 11
+        "X", 12
         -- </badutf-3.5>
     })
 
@@ -265,7 +265,7 @@ test:do_test(
         return test:execsql2("SELECT length('\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80') AS x")
     end, {
         -- <badutf-3.6>
-        "X", 10
+        "X", 11
         -- </badutf-3.6>
     })
 



More information about the Tarantool-patches mailing list