|
|
65878a |
From 91eda57764f26d3ebdbf8194a528d8d60d0f409a Mon Sep 17 00:00:00 2001
|
|
|
65878a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
65878a |
Date: Sat, 5 Oct 2013 22:47:52 -0400
|
|
|
65878a |
Subject: [PATCH] utf8: fix utf8_is_printable
|
|
|
65878a |
|
|
|
65878a |
---
|
|
|
65878a |
src/shared/utf8.c | 5 +++--
|
|
|
65878a |
src/test/test-utf8.c | 1 +
|
|
|
65878a |
2 files changed, 4 insertions(+), 2 deletions(-)
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/shared/utf8.c b/src/shared/utf8.c
|
|
|
65878a |
index a8e28ac..31120af 100644
|
|
|
65878a |
--- a/src/shared/utf8.c
|
|
|
65878a |
+++ b/src/shared/utf8.c
|
|
|
65878a |
@@ -141,14 +141,15 @@ bool utf8_is_printable(const char* str, size_t length) {
|
|
|
65878a |
|
|
|
65878a |
assert(str);
|
|
|
65878a |
|
|
|
65878a |
- for (p = (const uint8_t*) str; length; p++) {
|
|
|
65878a |
+ for (p = (const uint8_t*) str; length;) {
|
|
|
65878a |
int encoded_len = utf8_encoded_valid_unichar((const char *)p);
|
|
|
65878a |
- int32_t val = utf8_encoded_to_unichar((const char*)p);
|
|
|
65878a |
+ int val = utf8_encoded_to_unichar((const char*)p);
|
|
|
65878a |
|
|
|
65878a |
if (encoded_len < 0 || val < 0 || is_unicode_control(val))
|
|
|
65878a |
return false;
|
|
|
65878a |
|
|
|
65878a |
length -= encoded_len;
|
|
|
65878a |
+ p += encoded_len;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
return true;
|
|
|
65878a |
diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c
|
|
|
65878a |
index 7bd0db1..f0182ee 100644
|
|
|
65878a |
--- a/src/test/test-utf8.c
|
|
|
65878a |
+++ b/src/test/test-utf8.c
|
|
|
65878a |
@@ -26,6 +26,7 @@ static void test_utf8_is_printable(void) {
|
|
|
65878a |
assert_se(utf8_is_printable("ascii is valid\tunicode", 22));
|
|
|
65878a |
assert_se(utf8_is_printable("\342\204\242", 3));
|
|
|
65878a |
assert_se(!utf8_is_printable("\341\204", 2));
|
|
|
65878a |
+ assert_se(utf8_is_printable("ąę", 4));
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
static void test_utf8_is_valid(void) {
|