[systemd-commits] src/shared src/test
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Sat Oct 5 20:03:34 PDT 2013
src/shared/utf8.c | 5 +++--
src/test/test-utf8.c | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
New commits:
commit a7176505e0083a073d03760f7b5435017a47c7c8
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sat Oct 5 22:47:52 2013 -0400
utf8: fix utf8_is_printable
diff --git a/src/shared/utf8.c b/src/shared/utf8.c
index a8e28ac..31120af 100644
--- a/src/shared/utf8.c
+++ b/src/shared/utf8.c
@@ -141,14 +141,15 @@ bool utf8_is_printable(const char* str, size_t length) {
assert(str);
- for (p = (const uint8_t*) str; length; p++) {
+ for (p = (const uint8_t*) str; length;) {
int encoded_len = utf8_encoded_valid_unichar((const char *)p);
- int32_t val = utf8_encoded_to_unichar((const char*)p);
+ int val = utf8_encoded_to_unichar((const char*)p);
if (encoded_len < 0 || val < 0 || is_unicode_control(val))
return false;
length -= encoded_len;
+ p += encoded_len;
}
return true;
diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c
index 7bd0db1..f0182ee 100644
--- a/src/test/test-utf8.c
+++ b/src/test/test-utf8.c
@@ -26,6 +26,7 @@ static void test_utf8_is_printable(void) {
assert_se(utf8_is_printable("ascii is valid\tunicode", 22));
assert_se(utf8_is_printable("\342\204\242", 3));
assert_se(!utf8_is_printable("\341\204", 2));
+ assert_se(utf8_is_printable("Ä
Ä", 4));
}
static void test_utf8_is_valid(void) {
More information about the systemd-commits
mailing list